From 6bbed85899d16b063df41ffc2cbf314402ad73e6 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Mon, 20 Nov 2017 17:08:29 +0300 Subject: Fixing Coverity warnings. CID 200496 CID 200494 CID 200490 CID 200489 CID 200483 CID 200482 CID 200472 CID 200465 --- src/nxt_list.h | 7 ++++--- src/nxt_main_process.c | 3 +++ src/nxt_port.c | 7 +++---- src/nxt_port_memory.c | 3 ++- src/nxt_process.c | 6 ++++++ src/nxt_python_wsgi.c | 4 ++-- src/nxt_runtime.c | 3 +++ 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/nxt_list.h b/src/nxt_list.h index f400a356..ecbb67a9 100644 --- a/src/nxt_list.h +++ b/src/nxt_list.h @@ -13,6 +13,7 @@ typedef struct nxt_list_part_s nxt_list_part_t; struct nxt_list_part_s { nxt_list_part_t *next; uintptr_t nelts; + char data[]; }; @@ -43,12 +44,12 @@ nxt_list_part(list) \ #define \ nxt_list_data(part) \ - nxt_pointer_to(part, sizeof(nxt_list_part_t)) + ((void *) part->data) #define \ nxt_list_first(list) \ - (void *) nxt_list_data(nxt_list_part(list)) + nxt_list_data(nxt_list_part(list)) nxt_inline void * @@ -80,7 +81,7 @@ nxt_list_elt(nxt_list_t *list, nxt_uint_t n) nxt_list_part_t *_part = nxt_list_part(list); \ \ do { \ - elt = (void *) nxt_list_data(_part); \ + elt = nxt_list_data(_part); \ \ for (_end = (elt + _part->nelts); elt != _end; elt++) { \ diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c index 7d0050c4..767d6063 100644 --- a/src/nxt_main_process.c +++ b/src/nxt_main_process.c @@ -808,6 +808,9 @@ nxt_main_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid) buf = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool, sizeof(pid)); + + nxt_assert(buf != NULL); + buf->mem.free = nxt_cpymem(buf->mem.free, &pid, sizeof(pid)); nxt_port_socket_write(task, port, NXT_PORT_MSG_REMOVE_PID, diff --git a/src/nxt_port.c b/src/nxt_port.c index c63ea01b..4a07657d 100644 --- a/src/nxt_port.c +++ b/src/nxt_port.c @@ -311,10 +311,9 @@ nxt_port_process_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) process->ready = 1; + nxt_assert(nxt_queue_is_empty(&process->ports) == 0); + port = nxt_process_port_first(process); - if (nxt_slow_path(port == NULL)) { - return; - } nxt_debug(task, "process %PI ready", msg->port_msg.pid); @@ -348,7 +347,7 @@ nxt_port_mmap_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) fail_close: - close(msg->fd); + nxt_fd_close(msg->fd); } diff --git a/src/nxt_port_memory.c b/src/nxt_port_memory.c index 71ab1d60..9f27ab09 100644 --- a/src/nxt_port_memory.c +++ b/src/nxt_port_memory.c @@ -191,7 +191,6 @@ nxt_port_incoming_port_mmap(nxt_task_t *task, nxt_process_t *process, fd, process->pid); port_mmap = NULL; - hdr = NULL; if (fstat(fd, &mmap_stat) == -1) { nxt_log(task, NXT_LOG_WARN, "fstat(%FD) failed %E", fd, nxt_errno); @@ -214,6 +213,8 @@ nxt_port_incoming_port_mmap(nxt_task_t *task, nxt_process_t *process, if (nxt_slow_path(mmap_handler == NULL)) { nxt_log(task, NXT_LOG_WARN, "failed to allocate mmap_handler"); + nxt_mem_munmap(mem, PORT_MMAP_SIZE); + return NULL; } diff --git a/src/nxt_process.c b/src/nxt_process.c index 4d0241ec..f1c00e4e 100644 --- a/src/nxt_process.c +++ b/src/nxt_process.c @@ -299,6 +299,8 @@ nxt_process_daemon(nxt_task_t *task) nxt_pid_t pid; const char *msg; + fd = -1; + /* * fork() followed by a parent process's exit() detaches a child process * from an init script or terminal shell process which has started the @@ -372,6 +374,10 @@ fail: nxt_log(task, NXT_LOG_CRIT, msg, nxt_errno); + if (fd != -1) { + nxt_fd_close(fd); + } + return NXT_ERROR; } diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c index 33d9456a..51d9d800 100644 --- a/src/nxt_python_wsgi.c +++ b/src/nxt_python_wsgi.c @@ -298,8 +298,8 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf) fail: - Py_DECREF(obj); - Py_DECREF(module); + Py_XDECREF(obj); + Py_XDECREF(module); return NXT_ERROR; } diff --git a/src/nxt_runtime.c b/src/nxt_runtime.c index 60ce45f6..d07a1b3b 100644 --- a/src/nxt_runtime.c +++ b/src/nxt_runtime.c @@ -1696,6 +1696,9 @@ nxt_runtime_process_get(nxt_runtime_t *rt, nxt_pid_t pid) process = nxt_runtime_process_new(rt); if (nxt_slow_path(process == NULL)) { + + nxt_thread_mutex_unlock(&rt->processes_mutex); + return NULL; } -- cgit