diff options
author | Valentin Bartenev <vbart@nginx.com> | 2021-10-27 20:37:34 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2021-10-27 20:37:34 +0300 |
commit | 1441f42b5d08a1f7a4b445b10c0adb101edf506d (patch) | |
tree | 370d8f67f4bdd858947f87984a5a94fd25593bff /src | |
parent | 561dbeb98d2574804c0918ae088a8f5a41418afb (diff) | |
download | unit-1441f42b5d08a1f7a4b445b10c0adb101edf506d.tar.gz unit-1441f42b5d08a1f7a4b445b10c0adb101edf506d.tar.bz2 |
Fixed memleaks if PID checks fail in nxt_port_incoming_port_mmap().
Memory allocated for "mem" and "mmap_handler" leaked in that case.
Also removed one dead assigment of "hdr" pointer.
Diffstat (limited to 'src')
-rw-r--r-- | src/nxt_port_memory.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/nxt_port_memory.c b/src/nxt_port_memory.c index ab2f826f..e799f860 100644 --- a/src/nxt_port_memory.c +++ b/src/nxt_port_memory.c @@ -232,6 +232,18 @@ nxt_port_incoming_port_mmap(nxt_task_t *task, nxt_process_t *process, hdr = mem; + if (nxt_slow_path(hdr->src_pid != process->pid + || hdr->dst_pid != nxt_pid)) + { + nxt_log(task, NXT_LOG_WARN, "unexpected pid in mmap header detected: " + "%PI != %PI or %PI != %PI", hdr->src_pid, process->pid, + hdr->dst_pid, nxt_pid); + + nxt_mem_munmap(mem, PORT_MMAP_SIZE); + + return NULL; + } + mmap_handler = nxt_zalloc(sizeof(nxt_port_mmap_handler_t)); if (nxt_slow_path(mmap_handler == NULL)) { nxt_log(task, NXT_LOG_WARN, "failed to allocate mmap_handler"); @@ -244,16 +256,6 @@ nxt_port_incoming_port_mmap(nxt_task_t *task, nxt_process_t *process, mmap_handler->hdr = hdr; mmap_handler->fd = -1; - if (nxt_slow_path(hdr->src_pid != process->pid - || hdr->dst_pid != nxt_pid)) - { - nxt_log(task, NXT_LOG_WARN, "unexpected pid in mmap header detected: " - "%PI != %PI or %PI != %PI", hdr->src_pid, process->pid, - hdr->dst_pid, nxt_pid); - - return NULL; - } - nxt_thread_mutex_lock(&process->incoming.mutex); port_mmap = nxt_port_mmap_at(&process->incoming, hdr->id); @@ -261,7 +263,6 @@ nxt_port_incoming_port_mmap(nxt_task_t *task, nxt_process_t *process, nxt_log(task, NXT_LOG_WARN, "failed to add mmap to incoming array"); nxt_mem_munmap(mem, PORT_MMAP_SIZE); - hdr = NULL; nxt_free(mmap_handler); mmap_handler = NULL; |