diff --git a/client_handler.c b/client_handler.c index 26615d4..0c70b6e 100644 --- a/client_handler.c +++ b/client_handler.c @@ -37,9 +37,10 @@ void* client_handler(void* args) { send(client, response->body, response->content_length, 0); send(client, "\r\n", 2, 0); - free(response); - return NULL; + free_http_response(response); + free(headers); } free(buffer); + free(args); return NULL; } \ No newline at end of file diff --git a/http_stuff.c b/http_stuff.c index 37ad863..fcd1179 100644 --- a/http_stuff.c +++ b/http_stuff.c @@ -216,6 +216,7 @@ char* response_headers_to_string(http_response* res) { strcat(response, "Content-Length: "); strcat(response, content_lenth_str); strcat(response, "\r\n\r\n"); + free(content_lenth_str); return response; } @@ -226,7 +227,7 @@ char* get_header_value_request(http_request* req, char* key) { return req->headers[i].value; } } - log_message(LOG_WARN, "Header %s not found\n", key); + log_message(LOG_WARN, "Header %s not found", key); return NULL; } diff --git a/request_handler.c b/request_handler.c index 8b3ac34..00facf6 100644 --- a/request_handler.c +++ b/request_handler.c @@ -68,11 +68,13 @@ void parse_http_request(char* request, int length, struct http_request* req) { req->method = DELETE; } else { log_message(LOG_ERROR, "Invalid packet (method), cannot parse"); + free(type); return; } req->method_str = (char*)malloc(type_end - type_start + 1); strncpy(req->method_str, type_start, type_end - type_start); req->method_str[type_end - type_start] = '\0'; + free(type); // Extract URL char* url_start = type_end + 1; diff --git a/response_builder.c b/response_builder.c index 8f70234..8be8699 100644 --- a/response_builder.c +++ b/response_builder.c @@ -37,6 +37,8 @@ void response_handle_get(http_request* req, http_response* res) { serve_404(res); return; } + + free(file_path); } void response_handle_post(http_request* req, http_response* res) { @@ -162,7 +164,7 @@ void response_build_static_file(char* file_path, content_type content_type, // Set content type string res->content_type = content_type_str; - log_message(LOG_INFO, "Serving %s\n", file_path); + log_message(LOG_INFO, "Serving %s", file_path); } void serve_404(http_response* res) {