From 5aadb0529e115af5080f0270ab7b073bcd3021aa Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 29 Jun 2016 14:42:59 +0100 Subject: [PATCH] [CritFix] Fix leak of shared memory fds and files --- src/libutil/http.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/libutil/http.c b/src/libutil/http.c index 0536da453..b87e02f15 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -2360,34 +2360,35 @@ rspamd_http_message_storage_cleanup (struct rspamd_http_message *msg) union _rspamd_storage_u *storage; struct stat st; - if (msg->body_buf.len != 0) { - if (msg->flags & RSPAMD_HTTP_FLAG_SHMEM) { - storage = &msg->body_buf.c; - - if (storage->shared.shm_fd != -1) { - g_assert (fstat (storage->shared.shm_fd, &st) != -1); + if (msg->flags & RSPAMD_HTTP_FLAG_SHMEM) { + storage = &msg->body_buf.c; - if (msg->body_buf.str != MAP_FAILED) { - munmap (msg->body_buf.str, st.st_size); - } + if (storage->shared.shm_fd != -1) { + g_assert (fstat (storage->shared.shm_fd, &st) != -1); - close (storage->shared.shm_fd); + if (msg->body_buf.str != MAP_FAILED) { + munmap (msg->body_buf.str, st.st_size); } - if (storage->shared.name != NULL) { - REF_RELEASE (storage->shared.name); - } + close (storage->shared.shm_fd); + } - storage->shared.shm_fd = -1; - msg->body_buf.str = MAP_FAILED; + if (storage->shared.name != NULL) { + REF_RELEASE (storage->shared.name); } - else { + + storage->shared.shm_fd = -1; + msg->body_buf.str = MAP_FAILED; + } + else { + if (msg->body_buf.c.normal) { rspamd_fstring_free (msg->body_buf.c.normal); - msg->body_buf.c.normal = NULL; } - msg->body_buf.len = 0; + msg->body_buf.c.normal = NULL; } + + msg->body_buf.len = 0; } void -- 2.39.5