perf map: Fix map reference count issues
authorIan Rogers <irogers@google.com>
Thu, 29 Feb 2024 06:20:48 +0000 (22:20 -0800)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 1 Mar 2024 02:06:00 +0000 (18:06 -0800)
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
tools/perf/util/maps.c
tools/perf/util/probe-event.c

index 53aea6d2ef9367c3289f8110cf146f54d06d17b7..ce13145a9f8e8d012e30bdc1973409f16c781aff 100644 (file)
@@ -611,14 +611,14 @@ struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp)
        struct symbol *result = NULL;
 
        /* Ensure map is loaded before using map->map_ip */
-       if (map != NULL && map__load(map) >= 0) {
-               if (mapp)
-                       *mapp = map;
-
+       if (map != NULL && map__load(map) >= 0)
                result = map__find_symbol(map, map__map_ip(map, addr));
-               if (!mapp)
-                       map__put(map);
-       }
+
+       if (mapp)
+               *mapp = map;
+       else
+               map__put(map);
+
        return result;
 }
 
index be71abe8b9b0a4069af42b46fdd825d8778952ef..2a0ad9ecf0a20efc70ddc4eb1d43e6419a4bde80 100644 (file)
@@ -2274,9 +2274,7 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
        ret = pp->function ? 0 : -ENOMEM;
 
 out:
-       if (map && !is_kprobe) {
-               map__put(map);
-       }
+       map__put(map);
 
        return ret;
 }