From ddaec4a2b9b7c8be74166525bdcdff115c80d7c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 1 Dec 2017 00:23:44 +0100 Subject: [PATCH] Clean-up: reduce scope of dyanamically-allocated string MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit tmpnew is only useful within the scope of the libdir check. It can be allocated and free()'d within that scope. Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/main.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 297db20ce..4c3a1796c 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -2440,11 +2440,10 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) break; case LTTNG_CONSUMER64_UST: { - char *tmpnew = NULL; - if (config.consumerd64_lib_dir.value) { char *tmp; size_t tmplen; + char *tmpnew; tmp = lttng_secure_getenv("LD_LIBRARY_PATH"); if (!tmp) { @@ -2462,9 +2461,9 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) strcat(tmpnew, tmp); } ret = setenv("LD_LIBRARY_PATH", tmpnew, 1); + free(tmpnew); if (ret) { ret = -errno; - free(tmpnew); goto error; } } @@ -2474,16 +2473,14 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) "--consumerd-err-sock", consumer_data->err_unix_sock_path, "--group", config.tracing_group_name.value, NULL); - free(tmpnew); break; } case LTTNG_CONSUMER32_UST: { - char *tmpnew = NULL; - if (config.consumerd32_lib_dir.value) { char *tmp; size_t tmplen; + char *tmpnew; tmp = lttng_secure_getenv("LD_LIBRARY_PATH"); if (!tmp) { @@ -2501,9 +2498,9 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) strcat(tmpnew, tmp); } ret = setenv("LD_LIBRARY_PATH", tmpnew, 1); + free(tmpnew); if (ret) { ret = -errno; - free(tmpnew); goto error; } } @@ -2513,7 +2510,6 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) "--consumerd-err-sock", consumer_data->err_unix_sock_path, "--group", config.tracing_group_name.value, NULL); - free(tmpnew); break; } default: -- 2.34.1