From 6ba3ee9756f0426e974236205e603ef2198e697f Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sun, 9 Sep 2018 23:27:50 -0400 Subject: [PATCH] Fix some memory leaks --- server/socket_server.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/socket_server.c b/server/socket_server.c index 7d6d265..4a71565 100644 --- a/server/socket_server.c +++ b/server/socket_server.c @@ -190,10 +190,28 @@ enum socket_result serve_one_request(int sock_fd) { enum socket_result read_result = get_all_remote_parts(client_fd, TYPE_SERVER, &message); if (read_result == RESULT_MALFORMED) { send_headers(400, client_fd, -1); + if (message.start_line != NULL) { + free(message.start_line); + } + if (message.contents != NULL) { + free(message.contents); + } + if (message.headers != NULL) { + free_headers(message.headers); + } close(client_fd); return RESULT_MALFORMED; } else if (read_result != RESULT_OK){ send_headers(500, client_fd, -1); + if (message.start_line != NULL) { + free(message.start_line); + } + if (message.contents != NULL) { + free(message.contents); + } + if (message.headers != NULL) { + free_headers(message.headers); + } close(client_fd); return RESULT_READ_ERROR; }