X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fview.c;h=e1e1564c16ebe9f0e3650a27ac80eac1d7c34638;hp=37fb4b8bc3a867ee06ff3e52b3c9155a7069e1a6;hb=6f04ed72990f6c72d16fd08d39feac0967da732e;hpb=6c1c0768320135c6936c371b09731851b508c023 diff --git a/src/bin/lttng/commands/view.c b/src/bin/lttng/commands/view.c index 37fb4b8bc..e1e1564c1 100644 --- a/src/bin/lttng/commands/view.c +++ b/src/bin/lttng/commands/view.c @@ -152,7 +152,7 @@ static char **alloc_argv_from_user_opts(char *opts, const char *trace_path) } while (*token != '\0'); /* Add two here for the NULL terminating element and trace path */ - argv = malloc(sizeof(char *) * (num_opts + 2)); + argv = zmalloc(sizeof(char *) * (num_opts + 2)); if (argv == NULL) { goto error; } @@ -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; } @@ -199,7 +209,7 @@ static char **alloc_argv_from_local_opts(const char **opts, size_t opts_len, size = sizeof(char *) * mem_len; /* Add two here for the trace_path and the NULL terminating element. */ - argv = malloc(size); + argv = zmalloc(size); if (argv == NULL) { 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; }