Skip to content

Commit

Permalink
perf evlist: Fix cpu/thread map leak
Browse files Browse the repository at this point in the history
Asan reported leak of cpu and thread maps as they have one more refcount
than released.  I found that after setting evlist maps it should release
it's refcount.

It seems to be broken from the beginning so I chose the original commit
as the culprit.  But not sure how it's applied to stable trees since
there are many changes in the code after that.

Fixes: 7e2ed09 ("perf evlist: Store pointer to the cpu and thread maps")
Fixes: 4112eb1 ("perf evlist: Default to syswide target when no thread/cpu maps set")
Signed-off-by: Namhyung Kim <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Ian Rogers <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
namhyung authored and acmel committed Sep 15, 2020
1 parent b033ab1 commit bfd1b83
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tools/perf/util/evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,10 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target)

perf_evlist__set_maps(&evlist->core, cpus, threads);

/* as evlist now has references, put count here */
perf_cpu_map__put(cpus);
perf_thread_map__put(threads);

return 0;

out_delete_threads:
Expand Down Expand Up @@ -1273,11 +1277,12 @@ static int perf_evlist__create_syswide_maps(struct evlist *evlist)
goto out_put;

perf_evlist__set_maps(&evlist->core, cpus, threads);
out:
return err;

perf_thread_map__put(threads);
out_put:
perf_cpu_map__put(cpus);
goto out;
out:
return err;
}

int evlist__open(struct evlist *evlist)
Expand Down

0 comments on commit bfd1b83

Please sign in to comment.