From 266d5669d85db26f74fdd6483f114fe20f1bbb7e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 9 Feb 2015 16:23:21 +0000 Subject: [PATCH] Fix memory leaks in HTTP code. --- src/libutil/http.c | 16 ++++++++++++++-- test/rspamd_http_test.c | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libutil/http.c b/src/libutil/http.c index d66511fd5..2f948f452 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -943,6 +943,7 @@ void rspamd_http_connection_free (struct rspamd_http_connection *conn) { struct rspamd_http_connection_private *priv; + struct rspamd_http_keypair *peer_key; priv = conn->priv; rspamd_http_connection_reset (conn); @@ -950,6 +951,10 @@ rspamd_http_connection_free (struct rspamd_http_connection *conn) if (priv->local_key) { REF_RELEASE (priv->local_key); } + if (priv->peer_key) { + peer_key = (struct rspamd_http_keypair *)priv->peer_key; + REF_RELEASE (peer_key); + } g_slice_free1 (sizeof (struct rspamd_http_connection_private), priv); g_slice_free1 (sizeof (struct rspamd_http_connection), conn); @@ -1319,6 +1324,9 @@ rspamd_http_message_free (struct rspamd_http_message *msg) if (msg->status != NULL) { g_string_free (msg->status, TRUE); } + if (msg->host != NULL) { + g_string_free (msg->host, TRUE); + } if (msg->peer_key != NULL) { rspamd_http_connection_key_unref (msg->peer_key); } @@ -1504,7 +1512,11 @@ rspamd_http_router_try_file (struct rspamd_http_connection_entry *entry, reply_msg = rspamd_http_new_message (HTTP_RESPONSE); reply_msg->date = time (NULL); reply_msg->code = 200; + reply_msg->body = g_string_sized_new (st.st_size); + reply_msg->body->len = st.st_size; + reply_msg->body_buf.len = st.st_size; + reply_msg->body_buf.str = reply_msg->body->str; if (read (fd, reply_msg->body->str, st.st_size) != st.st_size) { close (fd); @@ -1512,8 +1524,8 @@ rspamd_http_router_try_file (struct rspamd_http_connection_entry *entry, return FALSE; } - reply_msg->body->len = st.st_size; - reply_msg->body->str[st.st_size] = '\0'; + reply_msg->body_buf.str[st.st_size] = '\0'; + close (fd); rspamd_http_connection_reset (entry->conn); diff --git a/test/rspamd_http_test.c b/test/rspamd_http_test.c index cdcfef967..77b71cee6 100644 --- a/test/rspamd_http_test.c +++ b/test/rspamd_http_test.c @@ -264,5 +264,5 @@ rspamd_http_test_func (void) close (fd); unlink (filepath); - kill (sfd, SIGKILL); + kill (sfd, SIGTERM); } -- 2.39.5