diff options
author | Tom Zanussi <tom.zanussi@linux.intel.com> | 2010-11-10 08:52:32 -0500 |
---|---|---|
committer | Tom Zanussi <tom.zanussi@linux.intel.com> | 2010-11-10 08:52:32 -0500 |
commit | e8719adf30c136319a77824d032b3a185148f8f9 (patch) | |
tree | 55773bb481e65568be3093aaf205303d3f01592d /tools/perf | |
parent | 01797c599816d39dfea47864c0f90cd50845811f (diff) |
perf trace scripting: fix some small memory leaks and missing error checks
Free the other two fields of script_desc which somehow got overlooked,
free malloc'ed args in case exec fails, and add missing checks for
failed mallocs.
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Acked-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/builtin-trace.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 2f8df45c4dcb..368e6249290a 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -337,6 +337,8 @@ static struct script_desc *script_desc__new(const char *name) | |||
337 | static void script_desc__delete(struct script_desc *s) | 337 | static void script_desc__delete(struct script_desc *s) |
338 | { | 338 | { |
339 | free(s->name); | 339 | free(s->name); |
340 | free(s->half_liner); | ||
341 | free(s->args); | ||
340 | free(s); | 342 | free(s); |
341 | } | 343 | } |
342 | 344 | ||
@@ -626,6 +628,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used) | |||
626 | close(live_pipe[0]); | 628 | close(live_pipe[0]); |
627 | 629 | ||
628 | __argv = malloc(6 * sizeof(const char *)); | 630 | __argv = malloc(6 * sizeof(const char *)); |
631 | if (!__argv) | ||
632 | die("malloc"); | ||
633 | |||
629 | __argv[0] = "/bin/sh"; | 634 | __argv[0] = "/bin/sh"; |
630 | __argv[1] = record_script_path; | 635 | __argv[1] = record_script_path; |
631 | __argv[2] = "-q"; | 636 | __argv[2] = "-q"; |
@@ -634,6 +639,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used) | |||
634 | __argv[5] = NULL; | 639 | __argv[5] = NULL; |
635 | 640 | ||
636 | execvp("/bin/sh", (char **)__argv); | 641 | execvp("/bin/sh", (char **)__argv); |
642 | free(__argv); | ||
637 | exit(-1); | 643 | exit(-1); |
638 | } | 644 | } |
639 | 645 | ||
@@ -641,6 +647,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used) | |||
641 | close(live_pipe[1]); | 647 | close(live_pipe[1]); |
642 | 648 | ||
643 | __argv = malloc((argc + 3) * sizeof(const char *)); | 649 | __argv = malloc((argc + 3) * sizeof(const char *)); |
650 | if (!__argv) | ||
651 | die("malloc"); | ||
644 | __argv[0] = "/bin/sh"; | 652 | __argv[0] = "/bin/sh"; |
645 | __argv[1] = report_script_path; | 653 | __argv[1] = report_script_path; |
646 | for (i = 2; i < argc; i++) | 654 | for (i = 2; i < argc; i++) |
@@ -650,6 +658,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used) | |||
650 | __argv[i++] = NULL; | 658 | __argv[i++] = NULL; |
651 | 659 | ||
652 | execvp("/bin/sh", (char **)__argv); | 660 | execvp("/bin/sh", (char **)__argv); |
661 | free(__argv); | ||
653 | exit(-1); | 662 | exit(-1); |
654 | } | 663 | } |
655 | 664 | ||
@@ -661,6 +670,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used) | |||
661 | } | 670 | } |
662 | 671 | ||
663 | __argv = malloc((argc + 1) * sizeof(const char *)); | 672 | __argv = malloc((argc + 1) * sizeof(const char *)); |
673 | if (!__argv) | ||
674 | die("malloc"); | ||
664 | __argv[0] = "/bin/sh"; | 675 | __argv[0] = "/bin/sh"; |
665 | __argv[1] = script_path; | 676 | __argv[1] = script_path; |
666 | for (i = 3; i < argc; i++) | 677 | for (i = 3; i < argc; i++) |
@@ -668,6 +679,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used) | |||
668 | __argv[argc - 1] = NULL; | 679 | __argv[argc - 1] = NULL; |
669 | 680 | ||
670 | execvp("/bin/sh", (char **)__argv); | 681 | execvp("/bin/sh", (char **)__argv); |
682 | free(__argv); | ||
671 | exit(-1); | 683 | exit(-1); |
672 | } | 684 | } |
673 | 685 | ||