Fix leaks and remove some non-standard functions

This commit is contained in:
Tobias Reisinger 2020-11-15 16:36:44 +01:00
parent c7cafa94c4
commit 97a19135ce
6 changed files with 63 additions and 27 deletions
src/handlers

View file

@ -45,11 +45,6 @@ send_response(struct mg_connection *nc, endpoint_response_t *response)
free(response_headers);
free(extra_headers);
if(response->alloced_content)
{
free((char*)response->content);
}
}
}
@ -83,8 +78,10 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
endpoint_t *endpoint = router_find_endpoint(hm->uri.p, hm->uri.len, &hm->method);
endpoint_response_t response;
response.content = NULL;
response.alloced_content = false;
M_RESPONSE_MSG(LOGGER_NONE, &response, 500, "server did not create a response");
M_RESPONSE_MSG(LOGGER_WARNING, &response, 500, "server did not create a response");
if(!endpoint)
{
@ -92,6 +89,7 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
if (!mg_normalize_uri_path(&hm->uri, &hm->uri)) {
mg_http_send_error(nc, 400, global_config->http_server_opts.extra_headers);
LOGGER_DEBUG("failed to normalize uri %.*s\n", hm->uri.len, hm->uri.p);
endpoint_response_free_content(&response);
return;
}
LOGGER_DEBUG("no endpoint found - serving file\n");
@ -116,6 +114,7 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
response.status_code = 0;
mg_serve_http(nc, hm, global_config->http_server_opts);
LOGGER_DEBUG("serving %.*s\n", hm->uri.len, hm->uri.p);
endpoint_response_free_content(&response);
return;
}
@ -147,6 +146,7 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
send_response(nc, &response);
}
endpoint_response_free_content(&response);
LOGGER_DEBUG("freeing endpoint args\n");
for(int i = 0; i < endpoint->args_count; ++i)
{