Fix: Possible call to execvp with NULL argument on allocation failure
[lttng-tools.git] / src / bin / lttng / commands / view.c
index c1a1323e5790732a198ca7b77b59c4dabf33df3c..dba614c2f5733cf59ce5f5c62aaf0c2fc44119c8 100644 (file)
@@ -160,6 +160,9 @@ static char **alloc_argv_from_user_opts(char *opts, const char *trace_path)
        token = strtok(opts, " ");
        while (token != NULL) {
                argv[i] = strdup(token);
+               if (argv[i] == NULL) {
+                       goto error;
+               }
                token = strtok(NULL, " ");
                i++;
        }
@@ -170,6 +173,13 @@ static char **alloc_argv_from_user_opts(char *opts, const char *trace_path)
        return argv;
 
 error:
+       if (argv) {
+               for (i = 0; i < num_opts + 2; i++) {
+                       free(argv[i]);
+               }
+               free(argv);
+       }
+
        return NULL;
 }
 
@@ -272,7 +282,7 @@ static int spawn_viewer(const char *trace_path)
                break;
        }
 
-       if (argv == NULL) {
+       if (argv == NULL || !viewer_bin) {
                ret = CMD_FATAL;
                goto error;
        }
@@ -306,14 +316,14 @@ static char *build_live_path(char *session_name)
 
        ret = gethostname(hostname, sizeof(hostname));
        if (ret < 0) {
-               perror("gethostname");
+               PERROR("gethostname");
                goto error;
        }
 
        ret = asprintf(&path, "net://localhost/host/%s/%s", hostname,
                        session_name);
        if (ret < 0) {
-               perror("asprintf live path");
+               PERROR("asprintf live path");
                goto error;
        }
 
This page took 0.023954 seconds and 4 git commands to generate.