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

perf unwind: Fix map reference counts

The result of thread__find_map is the map in the passed in
addr_location. Calling addr_location__exit puts that map and so copies
need to do a map__get. Add in the corresponding map__puts.

v2. Add missing map__put when dso is missing.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Ivan Babrou <ivan@cloudflare.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Link: https://lore.kernel.org/r/20230623043107.4077510-1-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
33941dbd e4ef3ef1

+12 -7
+12 -7
tools/perf/util/unwind-libunwind-local.c
··· 419 419 struct map *ret; 420 420 421 421 addr_location__init(&al); 422 - ret = thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al); 422 + thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al); 423 + ret = map__get(al.map); 423 424 addr_location__exit(&al); 424 425 return ret; 425 426 } ··· 441 440 return -EINVAL; 442 441 443 442 dso = map__dso(map); 444 - if (!dso) 443 + if (!dso) { 444 + map__put(map); 445 445 return -EINVAL; 446 + } 446 447 447 448 pr_debug("unwind: find_proc_info dso %s\n", dso->name); 448 449 ··· 479 476 480 477 memset(&di, 0, sizeof(di)); 481 478 if (dwarf_find_debug_frame(0, &di, ip, base, symfile, start, map__end(map))) 482 - return dwarf_search_unwind_table(as, ip, &di, pi, 483 - need_unwind_info, arg); 479 + ret = dwarf_search_unwind_table(as, ip, &di, pi, 480 + need_unwind_info, arg); 484 481 } 485 482 #endif 486 - 483 + map__put(map); 487 484 return ret; 488 485 } 489 486 ··· 537 534 538 535 dso = map__dso(map); 539 536 540 - if (!dso) 537 + if (!dso) { 538 + map__put(map); 541 539 return -1; 540 + } 542 541 543 542 size = dso__data_read_addr(dso, map, ui->machine, 544 543 addr, (u8 *) data, sizeof(*data)); 545 - 544 + map__put(map); 546 545 return !(size == sizeof(*data)); 547 546 } 548 547