Fixing Coverity warnings.

CID 200496
CID 200494
CID 200490
CID 200489
CID 200483
CID 200482
CID 200472
CID 200465
This commit is contained in:
Max Romanov
2017-11-20 17:08:29 +03:00
parent fa76ea700f
commit 6bbed85899
7 changed files with 23 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ typedef struct nxt_list_part_s nxt_list_part_t;
struct nxt_list_part_s { struct nxt_list_part_s {
nxt_list_part_t *next; nxt_list_part_t *next;
uintptr_t nelts; uintptr_t nelts;
char data[];
}; };
@@ -43,12 +44,12 @@ nxt_list_part(list) \
#define \ #define \
nxt_list_data(part) \ nxt_list_data(part) \
nxt_pointer_to(part, sizeof(nxt_list_part_t)) ((void *) part->data)
#define \ #define \
nxt_list_first(list) \ nxt_list_first(list) \
(void *) nxt_list_data(nxt_list_part(list)) nxt_list_data(nxt_list_part(list))
nxt_inline void * 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); \ nxt_list_part_t *_part = nxt_list_part(list); \
\ \
do { \ do { \
elt = (void *) nxt_list_data(_part); \ elt = nxt_list_data(_part); \
\ \
for (_end = (elt + _part->nelts); elt != _end; elt++) { \ for (_end = (elt + _part->nelts); elt != _end; elt++) { \

View File

@@ -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, buf = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool,
sizeof(pid)); sizeof(pid));
nxt_assert(buf != NULL);
buf->mem.free = nxt_cpymem(buf->mem.free, &pid, sizeof(pid)); buf->mem.free = nxt_cpymem(buf->mem.free, &pid, sizeof(pid));
nxt_port_socket_write(task, port, NXT_PORT_MSG_REMOVE_PID, nxt_port_socket_write(task, port, NXT_PORT_MSG_REMOVE_PID,

View File

@@ -311,10 +311,9 @@ nxt_port_process_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
process->ready = 1; process->ready = 1;
nxt_assert(nxt_queue_is_empty(&process->ports) == 0);
port = nxt_process_port_first(process); port = nxt_process_port_first(process);
if (nxt_slow_path(port == NULL)) {
return;
}
nxt_debug(task, "process %PI ready", msg->port_msg.pid); 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: fail_close:
close(msg->fd); nxt_fd_close(msg->fd);
} }

View File

@@ -191,7 +191,6 @@ nxt_port_incoming_port_mmap(nxt_task_t *task, nxt_process_t *process,
fd, process->pid); fd, process->pid);
port_mmap = NULL; port_mmap = NULL;
hdr = NULL;
if (fstat(fd, &mmap_stat) == -1) { if (fstat(fd, &mmap_stat) == -1) {
nxt_log(task, NXT_LOG_WARN, "fstat(%FD) failed %E", fd, nxt_errno); 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)) { if (nxt_slow_path(mmap_handler == NULL)) {
nxt_log(task, NXT_LOG_WARN, "failed to allocate mmap_handler"); nxt_log(task, NXT_LOG_WARN, "failed to allocate mmap_handler");
nxt_mem_munmap(mem, PORT_MMAP_SIZE);
return NULL; return NULL;
} }

View File

@@ -299,6 +299,8 @@ nxt_process_daemon(nxt_task_t *task)
nxt_pid_t pid; nxt_pid_t pid;
const char *msg; const char *msg;
fd = -1;
/* /*
* fork() followed by a parent process's exit() detaches a child process * fork() followed by a parent process's exit() detaches a child process
* from an init script or terminal shell process which has started the * 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); nxt_log(task, NXT_LOG_CRIT, msg, nxt_errno);
if (fd != -1) {
nxt_fd_close(fd);
}
return NXT_ERROR; return NXT_ERROR;
} }

View File

@@ -298,8 +298,8 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
fail: fail:
Py_DECREF(obj); Py_XDECREF(obj);
Py_DECREF(module); Py_XDECREF(module);
return NXT_ERROR; return NXT_ERROR;
} }

View File

@@ -1696,6 +1696,9 @@ nxt_runtime_process_get(nxt_runtime_t *rt, nxt_pid_t pid)
process = nxt_runtime_process_new(rt); process = nxt_runtime_process_new(rt);
if (nxt_slow_path(process == NULL)) { if (nxt_slow_path(process == NULL)) {
nxt_thread_mutex_unlock(&rt->processes_mutex);
return NULL; return NULL;
} }