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

perf maps: Make delete static, always use put

Address/leak sanitizer with reference count checking can identify the
location of leaks, so use put rather than delete to avoid free-ing
memory when the reference count is >1. Add maps__zput to ensure the
variable is cleared.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ali Saidi <alisaidi@amazon.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Brian Robbins <brianrob@linux.microsoft.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
Cc: Fangrui Song <maskray@google.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ivan Babrou <ivan@cloudflare.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Wenyu Liu <liuwenyu7@huawei.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
Cc: Yuan Can <yuancan@huawei.com>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230608232823.4027869-5-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
46125590 ee84a303

+11 -4
+1 -1
tools/perf/tests/maps.c
··· 140 140 ret = check_maps(merged3, ARRAY_SIZE(merged3), maps); 141 141 TEST_ASSERT_VAL("merge check failed", !ret); 142 142 143 - maps__delete(maps); 143 + maps__zput(maps); 144 144 return TEST_OK; 145 145 } 146 146
+1 -1
tools/perf/util/machine.c
··· 248 248 return; 249 249 250 250 machine__destroy_kernel_maps(machine); 251 - maps__delete(machine->kmaps); 251 + maps__zput(machine->kmaps); 252 252 dsos__exit(&machine->dsos); 253 253 machine__exit_vdso(machine); 254 254 zfree(&machine->root_dir);
+1 -1
tools/perf/util/maps.c
··· 171 171 return result; 172 172 } 173 173 174 - void maps__delete(struct maps *maps) 174 + static void maps__delete(struct maps *maps) 175 175 { 176 176 maps__exit(maps); 177 177 unwind__finish_access(maps);
+8 -1
tools/perf/util/maps.h
··· 57 57 }; 58 58 59 59 struct maps *maps__new(struct machine *machine); 60 - void maps__delete(struct maps *maps); 61 60 bool maps__empty(struct maps *maps); 62 61 int maps__clone(struct thread *thread, struct maps *parent); 63 62 64 63 struct maps *maps__get(struct maps *maps); 65 64 void maps__put(struct maps *maps); 65 + 66 + static inline void __maps__zput(struct maps **map) 67 + { 68 + maps__put(*map); 69 + *map = NULL; 70 + } 71 + 72 + #define maps__zput(map) __maps__zput(&map) 66 73 67 74 static inline struct rb_root *maps__entries(struct maps *maps) 68 75 {