]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Cleanup message when assiging body
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 10 Jun 2016 15:22:30 +0000 (16:22 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 10 Jun 2016 15:22:30 +0000 (16:22 +0100)
src/libutil/http.c

index 5417110d992569de050335f0d8a6bfc189073906..bff41d0c9191b4c987d56b8ea5dc8490fc8a1b17 100644 (file)
@@ -96,6 +96,8 @@ static const rspamd_ftok_t last_modified_header = {
                .len = 13
 };
 
+static void rspamd_http_message_storage_cleanup (struct rspamd_http_message *msg);
+
 #define HTTP_ERROR http_error_quark ()
 GQuark
 http_error_quark (void)
@@ -1947,6 +1949,8 @@ rspamd_http_message_set_body (struct rspamd_http_message *msg,
        union _rspamd_storage_u *storage;
        storage = &msg->body_buf.c;
 
+       rspamd_http_message_storage_cleanup (msg);
+
        if (msg->flags & RSPAMD_HTTP_FLAG_SHMEM) {
                storage->shared.shm_name = g_strdup ("/rhm.XXXXXXXXXXXXXXXXXXXX");
                storage->shared.shm_fd = rspamd_shmem_mkstemp (storage->shared.shm_name);
@@ -2010,6 +2014,8 @@ rspamd_http_message_set_body_from_fd (struct rspamd_http_message *msg,
        union _rspamd_storage_u *storage;
        struct stat st;
 
+       rspamd_http_message_storage_cleanup (msg);
+
        storage = &msg->body_buf.c;
        msg->flags |= RSPAMD_HTTP_FLAG_SHMEM|RSPAMD_HTTP_FLAG_SHMEM_IMMUTABLE;
 
@@ -2044,6 +2050,8 @@ rspamd_http_message_set_body_from_fstring_steal (struct rspamd_http_message *msg
 {
        union _rspamd_storage_u *storage;
 
+       rspamd_http_message_storage_cleanup (msg);
+
        storage = &msg->body_buf.c;
        msg->flags &= ~(RSPAMD_HTTP_FLAG_SHMEM|RSPAMD_HTTP_FLAG_SHMEM_IMMUTABLE);
 
@@ -2061,6 +2069,8 @@ rspamd_http_message_set_body_from_fstring_copy (struct rspamd_http_message *msg,
 {
        union _rspamd_storage_u *storage;
 
+       rspamd_http_message_storage_cleanup (msg);
+
        storage = &msg->body_buf.c;
        msg->flags &= ~(RSPAMD_HTTP_FLAG_SHMEM|RSPAMD_HTTP_FLAG_SHMEM_IMMUTABLE);
 
@@ -2130,22 +2140,12 @@ rspamd_http_message_append_body (struct rspamd_http_message *msg,
        return TRUE;
 }
 
-
-void
-rspamd_http_message_free (struct rspamd_http_message *msg)
+static void
+rspamd_http_message_storage_cleanup (struct rspamd_http_message *msg)
 {
-       struct rspamd_http_header *hdr, *htmp;
        union _rspamd_storage_u *storage;
        struct stat st;
 
-       HASH_ITER (hh, msg->headers, hdr, htmp) {
-               HASH_DEL (msg->headers, hdr);
-               rspamd_fstring_free (hdr->combined);
-               g_slice_free1 (sizeof (*hdr->name), hdr->name);
-               g_slice_free1 (sizeof (*hdr->value), hdr->value);
-               g_slice_free1 (sizeof (struct rspamd_http_header), hdr);
-       }
-
        if (msg->body_buf.len != 0) {
                if (msg->flags & RSPAMD_HTTP_FLAG_SHMEM) {
                        storage = &msg->body_buf.c;
@@ -2164,12 +2164,36 @@ rspamd_http_message_free (struct rspamd_http_message *msg)
                                shm_unlink (storage->shared.shm_name);
                                g_free (storage->shared.shm_name);
                        }
+
+                       storage->shared.shm_fd = -1;
+                       msg->body_buf.str = MAP_FAILED;
                }
                else {
                        rspamd_fstring_free (msg->body_buf.c.normal);
+                       msg->body_buf.c.normal = NULL;
                }
+
+               msg->body_buf.len = 0;
+       }
+}
+
+void
+rspamd_http_message_free (struct rspamd_http_message *msg)
+{
+       struct rspamd_http_header *hdr, *htmp;
+
+
+       HASH_ITER (hh, msg->headers, hdr, htmp) {
+               HASH_DEL (msg->headers, hdr);
+               rspamd_fstring_free (hdr->combined);
+               g_slice_free1 (sizeof (*hdr->name), hdr->name);
+               g_slice_free1 (sizeof (*hdr->value), hdr->value);
+               g_slice_free1 (sizeof (struct rspamd_http_header), hdr);
        }
 
+
+       rspamd_http_message_storage_cleanup (msg);
+
        if (msg->url != NULL) {
                rspamd_fstring_free (msg->url);
        }