Skip to content

Commit 1297b09

Browse files
committed
Fix file serving.
1 parent 66ba18c commit 1297b09

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lwan-serve-files.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,14 @@ _serve_file_stream(lwan_t* l, lwan_request_t *request, void *data)
108108
lwan_http_status_t
109109
serve_files(lwan_request_t *request, void *root_directory)
110110
{
111-
lwan_response_t *response;
111+
lwan_response_t *response = NULL;
112112
lwan_http_status_t return_status = HTTP_OK;
113113
char path_to_canonicalize[PATH_MAX];
114114
char *canonical_path;
115115
char *canonical_root;
116116

117+
lwan_request_set_response(request, response);
118+
117119
/* FIXME: ``canonical_root'' should be cached somewhere. */
118120
canonical_root = canonicalize_file_name(root_directory);
119121
if (!canonical_root)
@@ -147,13 +149,24 @@ serve_files(lwan_request_t *request, void *root_directory)
147149
}
148150

149151
response = calloc(1, sizeof(*response));
152+
if (!response) {
153+
free(canonical_path);
154+
return_status = HTTP_INTERNAL_ERROR;
155+
goto end_no_reset_stream_content;
156+
}
157+
150158
response->mime_type = (char*)lwan_determine_mime_type_for_file_name(canonical_path);
151159
response->stream_content.callback = _serve_file_stream;
152160
response->stream_content.data = canonical_path;
153161

154162
lwan_request_set_response(request, response);
163+
goto end_no_reset_stream_content;
155164

156165
end:
166+
if (response)
167+
request->response->stream_content.callback = NULL;
168+
169+
end_no_reset_stream_content:
157170
free(canonical_root);
158171

159172
return return_status;

0 commit comments

Comments
 (0)