Skip to content

Commit

Permalink
perf: Fix a memory leak in perf event handling
Browse files Browse the repository at this point in the history
This patch is to fix the following memory leak.

  $ uftrace record t-abc
  $ uftrace report -t 3us --no-pager
    Total time   Self time       Calls  Function
    ==========  ==========  ==========  ====================
      4.163 us    1.000 us           1  main
      3.163 us    3.163 us           1  a

  =================================================================
  ==78057==ERROR: LeakSanitizer: detected memory leaks

  Direct leak of 6 byte(s) in 1 object(s) allocated from:
      #0 0x7f6c4cf5734f in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x6234f)
      #1 0x498e46 in process_perf_event /home/honggyu/work/uftrace/utils/perf.c:576
      #2 0x487755 in __read_rstack /home/honggyu/work/uftrace/utils/fstack.c:2060
      #3 0x488445 in read_rstack /home/honggyu/work/uftrace/utils/fstack.c:2210
      #4 0x440503 in build_function_tree /home/honggyu/work/uftrace/cmds/report.c:117
      #5 0x440ba3 in report_functions /home/honggyu/work/uftrace/cmds/report.c:227
      #6 0x4442ca in command_report /home/honggyu/work/uftrace/cmds/report.c:692
      #7 0x40b843 in main /home/honggyu/work/uftrace/uftrace.c:1190
      #8 0x7f6c4b8dd82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

  SUMMARY: AddressSanitizer: 6 byte(s) leaked in 1 allocation(s).

Fixed: namhyung#1023

Signed-off-by: Honggyu Kim <[email protected]>
  • Loading branch information
honggyukim committed Nov 28, 2019
1 parent 9eafadf commit 9b311a4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions utils/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ void process_perf_event(struct uftrace_data *handle)
if (unlikely(task == NULL || task->fp == NULL))
continue;

args.data = NULL;

if (perf->type == PERF_RECORD_COMM) {
rec->more = 1;
args.args = NULL;
Expand Down Expand Up @@ -605,6 +607,7 @@ void process_perf_event(struct uftrace_data *handle)
add_it:
add_to_rstack_list(&task->event_list, rec, &args);
perf->valid = false;
free(args.data);
}

handle->perf_event_processed = true;
Expand Down

0 comments on commit 9b311a4

Please sign in to comment.