projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: Memory leak on error in alloc_argv_from_user_opts()
[lttng-tools.git]
/
src
/
bin
/
lttng
/
commands
/
view.c
diff --git
a/src/bin/lttng/commands/view.c
b/src/bin/lttng/commands/view.c
index dcd4d66245fb5049fa241c00feb771fdf52d93ba..1de6940aa8c1612342ba53a56f9e36c7329609e5 100644
(file)
--- a/
src/bin/lttng/commands/view.c
+++ b/
src/bin/lttng/commands/view.c
@@
-16,6
+16,7
@@
*/
#define _GNU_SOURCE
*/
#define _GNU_SOURCE
+#define _LGPL_SOURCE
#include <popt.h>
#include <stdio.h>
#include <stdlib.h>
#include <popt.h>
#include <stdio.h>
#include <stdlib.h>
@@
-151,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 */
} while (*token != '\0');
/* Add two here for the NULL terminating element and trace path */
- argv = malloc(sizeof(char *) * (num_opts + 2));
+ argv =
z
malloc(sizeof(char *) * (num_opts + 2));
if (argv == NULL) {
goto error;
}
if (argv == NULL) {
goto error;
}
@@
-159,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);
token = strtok(opts, " ");
while (token != NULL) {
argv[i] = strdup(token);
+ if (argv[i] == NULL) {
+ goto error;
+ }
token = strtok(NULL, " ");
i++;
}
token = strtok(NULL, " ");
i++;
}
@@
-169,6
+173,13
@@
static char **alloc_argv_from_user_opts(char *opts, const char *trace_path)
return argv;
error:
return argv;
error:
+ if (argv) {
+ for (i = 0; i < num_opts + 2; i++) {
+ free(argv[i]);
+ }
+ free(argv);
+ }
+
return NULL;
}
return NULL;
}
@@
-198,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. */
size = sizeof(char *) * mem_len;
/* Add two here for the trace_path and the NULL terminating element. */
- argv = malloc(size);
+ argv =
z
malloc(size);
if (argv == NULL) {
goto error;
}
if (argv == NULL) {
goto error;
}
This page took
0.024923 seconds
and
4
git commands to generate.