Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf map: Fix map reference count issues

The find will get the map, ensure puts are done on all paths.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240229062048.558799-1-irogers@google.com

authored by

Ian Rogers and committed by
Namhyung Kim
ec42d3d5 1947b924

+8 -10
+7 -7
tools/perf/util/maps.c
··· 611 611 struct symbol *result = NULL; 612 612 613 613 /* Ensure map is loaded before using map->map_ip */ 614 - if (map != NULL && map__load(map) >= 0) { 615 - if (mapp) 616 - *mapp = map; 617 - 614 + if (map != NULL && map__load(map) >= 0) 618 615 result = map__find_symbol(map, map__map_ip(map, addr)); 619 - if (!mapp) 620 - map__put(map); 621 - } 616 + 617 + if (mapp) 618 + *mapp = map; 619 + else 620 + map__put(map); 621 + 622 622 return result; 623 623 } 624 624
+1 -3
tools/perf/util/probe-event.c
··· 2274 2274 ret = pp->function ? 0 : -ENOMEM; 2275 2275 2276 2276 out: 2277 - if (map && !is_kprobe) { 2278 - map__put(map); 2279 - } 2277 + map__put(map); 2280 2278 2281 2279 return ret; 2282 2280 }