X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbin%2Flttng%2Fcommands%2Fview.c;h=e46c7052392103f43f9df3965b21cd6efe9b85cb;hb=8ad1d491d1773d92cbac0252a6c0e183bb9f9189;hp=adedf298966c0c7fad786f13bb34a66f4698a6de;hpb=8960e9cd5adb7e5cdaece135530a457cd65324dc;p=lttng-tools.git diff --git a/src/bin/lttng/commands/view.c b/src/bin/lttng/commands/view.c index adedf2989..e46c70523 100644 --- a/src/bin/lttng/commands/view.c +++ b/src/bin/lttng/commands/view.c @@ -151,7 +151,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; } @@ -159,6 +159,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++; } @@ -169,6 +172,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; } @@ -198,7 +208,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; }