Clean-up: reduce scope of dyanamically-allocated string
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 30 Nov 2017 23:23:44 +0000 (00:23 +0100)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 30 Nov 2017 23:23:44 +0000 (00:23 +0100)
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 <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/main.c

index 297db20ce062201630bd96ab91f268b79897916b..4c3a1796c8aa58abac502fbee00195b68c0d262d 100644 (file)
@@ -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:
This page took 0.029617 seconds and 4 git commands to generate.