diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-06-29 14:42:59 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-06-29 14:42:59 +0100 |
commit | 5aadb0529e115af5080f0270ab7b073bcd3021aa (patch) | |
tree | c390a122a8af6c05494f145233991c86cdb1d90a | |
parent | 72dabec06849a0b6db6bcf009a63a7e3c08b7563 (diff) | |
download | rspamd-5aadb0529e115af5080f0270ab7b073bcd3021aa.tar.gz rspamd-5aadb0529e115af5080f0270ab7b073bcd3021aa.zip |
[CritFix] Fix leak of shared memory fds and files
-rw-r--r-- | src/libutil/http.c | 37 |
1 files 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 |