]> source.dussan.org Git - rspamd.git/commitdiff
Fix memory leaks in HTTP code.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 9 Feb 2015 16:23:21 +0000 (16:23 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 9 Feb 2015 16:23:21 +0000 (16:23 +0000)
src/libutil/http.c
test/rspamd_http_test.c

index d66511fd546227469d7f724f2ec2d2e30b9e8b9c..2f948f452c5bd24655faf687445680a08d3b6f9c 100644 (file)
@@ -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);
index cdcfef967f0f7458863322070f38641f13779d8f..77b71cee60ec75ba5aa3e62654f9d933d1781863 100644 (file)
@@ -264,5 +264,5 @@ rspamd_http_test_func (void)
 
        close (fd);
        unlink (filepath);
-       kill (sfd, SIGKILL);
+       kill (sfd, SIGTERM);
 }