From 9173b78be5fee9308f302de890fc43363b29f160 Mon Sep 17 00:00:00 2001 From: RanierV <34061020+RanierV@users.noreply.github.com> Date: Fri, 1 Dec 2017 15:57:48 -0200 Subject: [PATCH] Update nxt_process_title.c CID 200480 (#2 of 2): Resource leak (RESOURCE_LEAK)22. leaked_storage: Variable p going out of scope leaks the storage it points to. --- src/nxt_process_title.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/nxt_process_title.c b/src/nxt_process_title.c index 3c20ac594..6be1ca930 100644 --- a/src/nxt_process_title.c +++ b/src/nxt_process_title.c @@ -116,11 +116,6 @@ nxt_process_arguments(nxt_task_t *task, char **orig_argv, char ***orig_envp) } } - p = nxt_malloc(strings_size); - if (p == NULL) { - return; - } - if (argv_end == end) { /* * There is no reason to modify environ if arguments @@ -130,6 +125,11 @@ nxt_process_arguments(nxt_task_t *task, char **orig_argv, char ***orig_envp) goto done; } + p = nxt_malloc(strings_size); + if (p == NULL) { + goto done; + } + end = argv[0]; for (i = 0; argv[i] != NULL; i++) { @@ -149,7 +149,7 @@ nxt_process_arguments(nxt_task_t *task, char **orig_argv, char ***orig_envp) env = nxt_malloc(environ_size); if (env == NULL) { - return; + goto done; } /* @@ -178,6 +178,12 @@ nxt_process_arguments(nxt_task_t *task, char **orig_argv, char ***orig_envp) } done: + if (p != NULL) { + nxt_free(p); + } + if (env != NULL) { + nxt_free(env); + } /* Preserve space for the trailing zero. */ end--;