aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-09 16:23:21 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-02-09 16:23:21 +0000
commit266d5669d85db26f74fdd6483f114fe20f1bbb7e (patch)
tree4b020a1f97bebaf1bbd7800a2882315eeca54a7f
parentc4e4a60be8bde947c7a93841fc90a9e31ebc6f1e (diff)
downloadrspamd-266d5669d85db26f74fdd6483f114fe20f1bbb7e.tar.gz
rspamd-266d5669d85db26f74fdd6483f114fe20f1bbb7e.zip
Fix memory leaks in HTTP code.
-rw-r--r--src/libutil/http.c16
-rw-r--r--test/rspamd_http_test.c2
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);
}