Skip to contentSkip to conversation

perf dlfilter: Avoid leak in v0 API test use of resolve_address()

PATCH New Adrian Hunter 1 participant 1 message Aug 30, 2023 perf events

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

PATCH 1/1 perf dlfilter: Avoid leak in v0 API test use of resolve_address()

The introduction of reference counting causes the v0 API perf_dlfilter_fns.resolve_address() to leak. v2 API introduced perf_dlfilter_fns.al_cleanup() to prevent that. For the v0 API, avoid the leak by exiting the addr_location immediately, since the documentation makes it clear that pointers obtained via perf_dlfilter_fns are not necessarily valid (dereferenceable) after 'filter_event' and 'filter_event_early' return.

---
 tools/perf/util/dlfilter.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/util/dlfilter.c +2 -0
index e0f822ebb9b9..1dbf27822ee2 100644
@@ -187,6 +187,8 @@ static __s32 dlfilter__resolve_address(void *ctx, __u64 address, struct perf_dlf
 
 	if (has_priv(d_al_p))
 		d_al_p->priv = memdup(&al, sizeof(al));
+	else /* Avoid leak for v0 API */
+		addr_location__exit(&al);
 
 	return 0;
 }
Signature · 1 line
2.34.1