Allocating process init struct from runtime memory pool.
This avoids memory leak reports from the address sanitizer.
This commit is contained in:
@@ -465,13 +465,11 @@ nxt_main_start_controller_process(nxt_task_t *task, nxt_runtime_t *rt)
|
|||||||
{
|
{
|
||||||
nxt_process_init_t *init;
|
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)) {
|
if (nxt_slow_path(init == NULL)) {
|
||||||
return NXT_ERROR;
|
return NXT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxt_memzero(init, sizeof(nxt_process_init_t));
|
|
||||||
|
|
||||||
init->start = nxt_controller_start;
|
init->start = nxt_controller_start;
|
||||||
init->name = "controller";
|
init->name = "controller";
|
||||||
init->user_cred = &rt->user_cred;
|
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;
|
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)) {
|
if (nxt_slow_path(init == NULL)) {
|
||||||
return NXT_ERROR;
|
return NXT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxt_memzero(init, sizeof(nxt_process_init_t));
|
|
||||||
|
|
||||||
init->start = nxt_discovery_start;
|
init->start = nxt_discovery_start;
|
||||||
init->name = "discovery";
|
init->name = "discovery";
|
||||||
init->user_cred = &rt->user_cred;
|
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;
|
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)) {
|
if (nxt_slow_path(init == NULL)) {
|
||||||
return NXT_ERROR;
|
return NXT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxt_memzero(init, sizeof(nxt_process_init_t));
|
|
||||||
|
|
||||||
init->start = nxt_router_start;
|
init->start = nxt_router_start;
|
||||||
init->name = "router";
|
init->name = "router";
|
||||||
init->user_cred = &rt->user_cred;
|
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;
|
+ app_conf->group.length + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
init = nxt_malloc(size);
|
init = nxt_mp_zalloc(rt->mem_pool, size);
|
||||||
if (nxt_slow_path(init == NULL)) {
|
if (nxt_slow_path(init == NULL)) {
|
||||||
return NXT_ERROR;
|
return NXT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxt_memzero(init, sizeof(nxt_process_init_t));
|
|
||||||
|
|
||||||
if (rt->capabilities.setid) {
|
if (rt->capabilities.setid) {
|
||||||
init->user_cred = nxt_pointer_to(init, sizeof(nxt_process_init_t));
|
init->user_cred = nxt_pointer_to(init, sizeof(nxt_process_init_t));
|
||||||
user = nxt_pointer_to(init->user_cred, sizeof(nxt_user_cred_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:
|
fail:
|
||||||
|
|
||||||
nxt_free(init);
|
nxt_mp_free(rt->mem_pool, init);
|
||||||
|
|
||||||
return NXT_ERROR;
|
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);
|
process = nxt_runtime_process_new(rt);
|
||||||
if (nxt_slow_path(process == NULL)) {
|
if (nxt_slow_path(process == NULL)) {
|
||||||
|
nxt_mp_free(rt->mem_pool, init);
|
||||||
|
|
||||||
return NXT_ERROR;
|
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) {
|
nxt_runtime_process_each(rt, process) {
|
||||||
|
|
||||||
if (nxt_pid != process->pid) {
|
if (nxt_pid != process->pid) {
|
||||||
process->init = NULL;
|
|
||||||
|
|
||||||
nxt_process_port_each(process, port) {
|
nxt_process_port_each(process, port) {
|
||||||
|
|
||||||
(void) nxt_port_socket_write(task, port, NXT_PORT_MSG_QUIT,
|
(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) {
|
if (process) {
|
||||||
init = process->init;
|
init = process->init;
|
||||||
|
process->init = NULL;
|
||||||
|
|
||||||
ptype = nxt_process_type(process);
|
ptype = nxt_process_type(process);
|
||||||
|
|
||||||
if (process->ready && init != NULL) {
|
if (process->ready) {
|
||||||
init->stream = 0;
|
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);
|
init->restart(task, rt, init);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
nxt_free(init);
|
nxt_mp_free(rt->mem_pool, init);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1318,6 +1318,10 @@ nxt_runtime_process_destroy(nxt_runtime_t *rt, nxt_process_t *process)
|
|||||||
nxt_thread_mutex_destroy(&process->outgoing.mutex);
|
nxt_thread_mutex_destroy(&process->outgoing.mutex);
|
||||||
nxt_thread_mutex_destroy(&process->cp_mutex);
|
nxt_thread_mutex_destroy(&process->cp_mutex);
|
||||||
|
|
||||||
|
if (process->init != NULL) {
|
||||||
|
nxt_mp_free(rt->mem_pool, process->init);
|
||||||
|
}
|
||||||
|
|
||||||
nxt_mp_free(rt->mem_pool, process);
|
nxt_mp_free(rt->mem_pool, process);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user