diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-07-29 13:08:55 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-07-29 13:08:55 -0400 |
commit | 39d17dacb3c25df878b56aa80a170d6088e041f9 (patch) | |
tree | 1f78086d224ae875c024c3dc8fda0948b776f69e /tools/perf | |
parent | 8c31a1e049a0c26f78558d7cc5a9ab6956c86694 (diff) |
perf record: Release resources at exit
So that we can reduce the noise on valgrind when looking for memory
leaks.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/builtin-record.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index b93879677cca..5ae0d93d8597 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -439,6 +439,7 @@ static void atexit_header(void) | |||
439 | 439 | ||
440 | process_buildids(); | 440 | process_buildids(); |
441 | perf_header__write(&session->header, output, true); | 441 | perf_header__write(&session->header, output, true); |
442 | perf_session__delete(session); | ||
442 | } | 443 | } |
443 | } | 444 | } |
444 | 445 | ||
@@ -558,12 +559,15 @@ static int __cmd_record(int argc, const char **argv) | |||
558 | if (!file_new) { | 559 | if (!file_new) { |
559 | err = perf_header__read(session, output); | 560 | err = perf_header__read(session, output); |
560 | if (err < 0) | 561 | if (err < 0) |
561 | return err; | 562 | goto out_delete_session; |
562 | } | 563 | } |
563 | 564 | ||
564 | if (have_tracepoints(attrs, nr_counters)) | 565 | if (have_tracepoints(attrs, nr_counters)) |
565 | perf_header__set_feat(&session->header, HEADER_TRACE_INFO); | 566 | perf_header__set_feat(&session->header, HEADER_TRACE_INFO); |
566 | 567 | ||
568 | /* | ||
569 | * perf_session__delete(session) will be called at atexit_header() | ||
570 | */ | ||
567 | atexit(atexit_header); | 571 | atexit(atexit_header); |
568 | 572 | ||
569 | if (forks) { | 573 | if (forks) { |
@@ -768,6 +772,10 @@ static int __cmd_record(int argc, const char **argv) | |||
768 | bytes_written / 24); | 772 | bytes_written / 24); |
769 | 773 | ||
770 | return 0; | 774 | return 0; |
775 | |||
776 | out_delete_session: | ||
777 | perf_session__delete(session); | ||
778 | return err; | ||
771 | } | 779 | } |
772 | 780 | ||
773 | static const char * const record_usage[] = { | 781 | static const char * const record_usage[] = { |
@@ -824,7 +832,7 @@ static const struct option options[] = { | |||
824 | 832 | ||
825 | int cmd_record(int argc, const char **argv, const char *prefix __used) | 833 | int cmd_record(int argc, const char **argv, const char *prefix __used) |
826 | { | 834 | { |
827 | int i,j; | 835 | int i, j, err = -ENOMEM; |
828 | 836 | ||
829 | argc = parse_options(argc, argv, options, record_usage, | 837 | argc = parse_options(argc, argv, options, record_usage, |
830 | PARSE_OPT_STOP_AT_NON_OPTION); | 838 | PARSE_OPT_STOP_AT_NON_OPTION); |
@@ -873,13 +881,13 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
873 | for (j = 0; j < MAX_COUNTERS; j++) { | 881 | for (j = 0; j < MAX_COUNTERS; j++) { |
874 | fd[i][j] = malloc(sizeof(int)*thread_num); | 882 | fd[i][j] = malloc(sizeof(int)*thread_num); |
875 | if (!fd[i][j]) | 883 | if (!fd[i][j]) |
876 | return -ENOMEM; | 884 | goto out_free_fd; |
877 | } | 885 | } |
878 | } | 886 | } |
879 | event_array = malloc( | 887 | event_array = malloc( |
880 | sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num); | 888 | sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num); |
881 | if (!event_array) | 889 | if (!event_array) |
882 | return -ENOMEM; | 890 | goto out_free_fd; |
883 | 891 | ||
884 | if (user_interval != ULLONG_MAX) | 892 | if (user_interval != ULLONG_MAX) |
885 | default_interval = user_interval; | 893 | default_interval = user_interval; |
@@ -895,8 +903,20 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
895 | default_interval = freq; | 903 | default_interval = freq; |
896 | } else { | 904 | } else { |
897 | fprintf(stderr, "frequency and count are zero, aborting\n"); | 905 | fprintf(stderr, "frequency and count are zero, aborting\n"); |
898 | exit(EXIT_FAILURE); | 906 | err = -EINVAL; |
907 | goto out_free_event_array; | ||
899 | } | 908 | } |
900 | 909 | ||
901 | return __cmd_record(argc, argv); | 910 | err = __cmd_record(argc, argv); |
911 | |||
912 | out_free_event_array: | ||
913 | free(event_array); | ||
914 | out_free_fd: | ||
915 | for (i = 0; i < MAX_NR_CPUS; i++) { | ||
916 | for (j = 0; j < MAX_COUNTERS; j++) | ||
917 | free(fd[i][j]); | ||
918 | } | ||
919 | free(all_tids); | ||
920 | all_tids = NULL; | ||
921 | return err; | ||
902 | } | 922 | } |