From: Vsevolod Stakhov Date: Fri, 10 Jun 2016 15:22:30 +0000 (+0100) Subject: [Fix] Cleanup message when assiging body X-Git-Tag: 1.3.0~379^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=de6e99a081384da39d119e15375febf0028cea9d;p=rspamd.git [Fix] Cleanup message when assiging body --- diff --git a/src/libutil/http.c b/src/libutil/http.c index 5417110d9..bff41d0c9 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -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); }