From 10cff3572b39f39861aa85fa04a44a01ea7e3fe1 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Mon, 3 Sep 2018 00:33:33 -0400 Subject: [PATCH] Fix leaks --- client/http_client.c | 1 + client/http_socket.c | 3 +++ common/socket_helper.c | 1 - 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/http_client.c b/client/http_client.c index 9025ea0..7ca330a 100644 --- a/client/http_client.c +++ b/client/http_client.c @@ -66,4 +66,5 @@ void get_parts(const char *dest, char *path_buffer, char *host_buffer) { } strcpy(path_buffer, slash_cursor); strncpy(host_buffer, dest, slash_cursor - dest); + host_buffer[slash_cursor - dest] = '\0'; } diff --git a/client/http_socket.c b/client/http_socket.c index e4dba8a..8cf73f7 100644 --- a/client/http_socket.c +++ b/client/http_socket.c @@ -142,6 +142,9 @@ enum socket_read_result send_request(struct http_message req, struct response_in res_info->rtt = end_time - start_time; res_info->contents = res.contents; close(socket_fd); + free(res.start_line); + free_headers(res.headers); + freeaddrinfo(addr_info); return result; } diff --git a/common/socket_helper.c b/common/socket_helper.c index 557b588..27e1aa9 100644 --- a/common/socket_helper.c +++ b/common/socket_helper.c @@ -86,7 +86,6 @@ static struct line_read_result read_line(const char *buffer, int buffer_size, st result.line_type = RESULT_START_LINE; message->start_line = malloc((line_size + 1) * sizeof(char)); strcpy(message->start_line, result.line); - message->start_line = result.line; } return result;