Commit c5f1fa15 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Greg Kroah-Hartman
Browse files

perf probe: Fix memory leakage when the probe point is not found

[ Upstream commit 12d572e785b15bc764e956caaa8a4c846fd15694 ]

Fix the memory leakage in debuginfo__find_trace_events() when the probe
point is not found in the debuginfo. If there is no probe point found in
the debuginfo, debuginfo__find_probes() will NOT return -ENOENT, but 0.

Thus the caller of debuginfo__find_probes() must check the tf.ntevs and
release the allocated memory for the array of struct probe_trace_event.

The current code releases the memory only if the debuginfo__find_probes()
hits an error but not checks tf.ntevs. In the result, the memory allocated
on *tevs are not released if tf.ntevs == 0.

This fixes the memory leakage by checking tf.ntevs == 0 in addition to
ret < 0.

Fixes: ff741783

 ("perf probe: Introduce debuginfo to encapsulate dwarf information")
Signed-off-by: default avatarMasami Hiramatsu <>
Reviewed-by: default avatarSrikar Dronamraju <>
Cc: Andi Kleen <>
Cc: Oleg Nesterov <>

Signed-off-by: default avatarArnaldo Carvalho de Melo <>
Signed-off-by: default avatarSasha Levin <>
parent 4e09fc7e
......@@ -1274,7 +1274,7 @@ int debuginfo__find_trace_events(struct debuginfo *dbg,
tf.ntevs = 0;
ret = debuginfo__find_probes(dbg, &;
if (ret < 0) {
if (ret < 0 || tf.ntevs == 0) {
for (i = 0; i < tf.ntevs; i++)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment