Skip to content

Commit fd81f52

Browse files
James-A-Clarkacmel
authored andcommitted
perf maps: Re-use __maps__free_maps_by_name()
maps__merge_in() hard codes the steps to free the maps_by_name list. It seems to not map__put() each element before freeing, and it sets maps_by_name_sorted to true after freeing, which may be harmless but is inconsistent with maps__init() and other functions. maps__maps_by_name_addr() is also quite hard to read because we already have maps__maps_by_name() and maps__maps_by_address(), but the function is only used in that place so delete it. Reviewed-by: Ian Rogers <[email protected]> Signed-off-by: James Clark <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 9fe410a commit fd81f52

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tools/perf/util/maps.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ static void maps__set_maps_by_address(struct maps *maps, struct map **new)
124124

125125
}
126126

127-
static struct map ***maps__maps_by_name_addr(struct maps *maps)
128-
{
129-
return &RC_CHK_ACCESS(maps)->maps_by_name;
130-
}
131-
132127
static void maps__set_nr_maps_allocated(struct maps *maps, unsigned int nr_maps_allocated)
133128
{
134129
RC_CHK_ACCESS(maps)->nr_maps_allocated = nr_maps_allocated;
@@ -284,13 +279,19 @@ void maps__put(struct maps *maps)
284279

285280
static void __maps__free_maps_by_name(struct maps *maps)
286281
{
282+
if (!maps__maps_by_name(maps))
283+
return;
284+
287285
/*
288286
* Free everything to try to do it from the rbtree in the next search
289287
*/
290288
for (unsigned int i = 0; i < maps__nr_maps(maps); i++)
291289
map__put(maps__maps_by_name(maps)[i]);
292290

293291
zfree(&RC_CHK_ACCESS(maps)->maps_by_name);
292+
293+
/* Consistent with maps__init(). When maps_by_name == NULL, maps_by_name_sorted == false */
294+
maps__set_maps_by_name_sorted(maps, false);
294295
}
295296

296297
static int map__start_cmp(const void *a, const void *b)
@@ -1167,8 +1168,7 @@ int maps__merge_in(struct maps *kmaps, struct map *new_map)
11671168
}
11681169
maps__set_maps_by_address(kmaps, merged_maps_by_address);
11691170
maps__set_maps_by_address_sorted(kmaps, true);
1170-
zfree(maps__maps_by_name_addr(kmaps));
1171-
maps__set_maps_by_name_sorted(kmaps, true);
1171+
__maps__free_maps_by_name(kmaps);
11721172
maps__set_nr_maps_allocated(kmaps, merged_nr_maps_allocated);
11731173

11741174
/* Copy entries before the new_map that can't overlap. */

0 commit comments

Comments
 (0)