summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_main_process.c
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2019-10-29 15:33:45 +0300
committerMax Romanov <max.romanov@nginx.com>2019-10-29 15:33:45 +0300
commit65b03a14a7b48ae0e1dc34b74e05f01574a5424f (patch)
tree78835d2701380aba35087fe432b4efd73c139dc3 /src/nxt_main_process.c
parent4a79e9631b06b82b1a14057fe6febcbd69d4ed4e (diff)
downloadunit-65b03a14a7b48ae0e1dc34b74e05f01574a5424f.tar.gz
unit-65b03a14a7b48ae0e1dc34b74e05f01574a5424f.tar.bz2
Allocating process init struct from runtime memory pool.
This avoids memory leak reports from the address sanitizer.
Diffstat (limited to 'src/nxt_main_process.c')
-rw-r--r--src/nxt_main_process.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c
index 4e55dcfa..b86fb1c1 100644
--- a/src/nxt_main_process.c
+++ b/src/nxt_main_process.c
@@ -465,13 +465,11 @@ nxt_main_start_controller_process(nxt_task_t *task, nxt_runtime_t *rt)
{
nxt_process_init_t *init;
- init = nxt_malloc(sizeof(nxt_process_init_t));
+ init = nxt_mp_zalloc(rt->mem_pool, sizeof(nxt_process_init_t));
if (nxt_slow_path(init == NULL)) {
return NXT_ERROR;
}
- nxt_memzero(init, sizeof(nxt_process_init_t));
-
init->start = nxt_controller_start;
init->name = "controller";
init->user_cred = &rt->user_cred;
@@ -561,13 +559,11 @@ nxt_main_start_discovery_process(nxt_task_t *task, nxt_runtime_t *rt)
{
nxt_process_init_t *init;
- init = nxt_malloc(sizeof(nxt_process_init_t));
+ init = nxt_mp_zalloc(rt->mem_pool, sizeof(nxt_process_init_t));
if (nxt_slow_path(init == NULL)) {
return NXT_ERROR;
}
- nxt_memzero(init, sizeof(nxt_process_init_t));
-
init->start = nxt_discovery_start;
init->name = "discovery";
init->user_cred = &rt->user_cred;
@@ -587,13 +583,11 @@ nxt_main_start_router_process(nxt_task_t *task, nxt_runtime_t *rt)
{
nxt_process_init_t *init;
- init = nxt_malloc(sizeof(nxt_process_init_t));
+ init = nxt_mp_zalloc(rt->mem_pool, sizeof(nxt_process_init_t));
if (nxt_slow_path(init == NULL)) {
return NXT_ERROR;
}
- nxt_memzero(init, sizeof(nxt_process_init_t));
-
init->start = nxt_router_start;
init->name = "router";
init->user_cred = &rt->user_cred;
@@ -627,13 +621,11 @@ nxt_main_start_worker_process(nxt_task_t *task, nxt_runtime_t *rt,
+ app_conf->group.length + 1;
}
- init = nxt_malloc(size);
+ init = nxt_mp_zalloc(rt->mem_pool, size);
if (nxt_slow_path(init == NULL)) {
return NXT_ERROR;
}
- nxt_memzero(init, sizeof(nxt_process_init_t));
-
if (rt->capabilities.setid) {
init->user_cred = nxt_pointer_to(init, sizeof(nxt_process_init_t));
user = nxt_pointer_to(init->user_cred, sizeof(nxt_user_cred_t));
@@ -705,7 +697,7 @@ nxt_main_start_worker_process(nxt_task_t *task, nxt_runtime_t *rt,
fail:
- nxt_free(init);
+ nxt_mp_free(rt->mem_pool, init);
return NXT_ERROR;
}
@@ -726,6 +718,8 @@ nxt_main_create_worker_process(nxt_task_t *task, nxt_runtime_t *rt,
process = nxt_runtime_process_new(rt);
if (nxt_slow_path(process == NULL)) {
+ nxt_mp_free(rt->mem_pool, init);
+
return NXT_ERROR;
}
@@ -785,8 +779,6 @@ nxt_main_stop_all_processes(nxt_task_t *task, nxt_runtime_t *rt)
nxt_runtime_process_each(rt, process) {
if (nxt_pid != process->pid) {
- process->init = NULL;
-
nxt_process_port_each(process, port) {
(void) nxt_port_socket_write(task, port, NXT_PORT_MSG_QUIT,
@@ -1005,10 +997,11 @@ nxt_main_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid)
if (process) {
init = process->init;
+ process->init = NULL;
ptype = nxt_process_type(process);
- if (process->ready && init != NULL) {
+ if (process->ready) {
init->stream = 0;
}
@@ -1057,7 +1050,7 @@ nxt_main_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid)
init->restart(task, rt, init);
} else {
- nxt_free(init);
+ nxt_mp_free(rt->mem_pool, init);
}
}
}