Skip to contentSkip to conversation

perf unwind: Fix map reference counts

PATCH Superseded Ian Rogers 2 participants 2 messages Jun 22, 2023 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 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.

---
 tools/perf/util/unwind-libunwind-local.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
tools/perf/util/unwind-libunwind-local.c +6 -5
index 36bf5100bad2..9cb82d7c7dc7 100644
@@ -419,7 +419,8 @@ static struct map *find_map(unw_word_t ip, struct unwind_info *ui)
 	struct map *ret;
 
 	addr_location__init(&al);
-	ret = thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al);
+	thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al);
+	ret = map__get(al.map);
 	addr_location__exit(&al);
 	return ret;
 }
@@ -476,11 +477,11 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
 
 		memset(&di, 0, sizeof(di));
 		if (dwarf_find_debug_frame(0, &di, ip, base, symfile, start, map__end(map)))
-			return dwarf_search_unwind_table(as, ip, &di, pi,
-							 need_unwind_info, arg);
+			ret = dwarf_search_unwind_table(as, ip, &di, pi,
+							need_unwind_info, arg);
 	}
 #endif
-
+	map__put(map);
 	return ret;
 }
 
@@ -539,7 +540,7 @@ static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
 
 	size = dso__data_read_addr(dso, map, ui->machine,
 				   addr, (u8 *) data, sizeof(*data));
-
+	map__put(map);
 	return !(size == sizeof(*data));
 }
 
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
maintainer
#1 lore raw
Quoted 4 lines · Ian Rogers

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.

It also needs map__put() when map__dso() returns NULL.

Thanks,
Namhyung

Quoted 47 lines
---
 tools/perf/util/unwind-libunwind-local.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
tools/perf/util/unwind-libunwind-local.c +6 -6
index 36bf5100bad2..9cb82d7c7dc7 100644
@@ -419,7 +419,8 @@ static struct map *find_map(unw_word_t ip, struct unwind_info *ui)
        struct map *ret;
 
        addr_location__init(&al);
-       ret = thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al);
+       thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al);
+       ret = map__get(al.map);
        addr_location__exit(&al);
        return ret;
 }
@@ -476,11 +477,11 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
 
                memset(&di, 0, sizeof(di));
                if (dwarf_find_debug_frame(0, &di, ip, base, symfile, start, map__end(map)))
-                       return dwarf_search_unwind_table(as, ip, &di, pi,
-                                                        need_unwind_info, arg);
+                       ret = dwarf_search_unwind_table(as, ip, &di, pi,
+                                                       need_unwind_info, arg);
        }
 #endif
-
+       map__put(map);
        return ret;
 }
 
@@ -539,7 +540,7 @@ static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
 
        size = dso__data_read_addr(dso, map, ui->machine,
                                   addr, (u8 *) data, sizeof(*data));
-
+       map__put(map);
        return !(size == sizeof(*data));
 }
 
--

2.41.0.162.gfafddb0af9-goog