提交 06aea225 编写于 作者: M Masami Hiramatsu 提交者: Yang Yingliang

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

stable inclusion
from linux-4.19.142
commit 6cb22ed4f00f73cb5e36581d42542ce1192c99b3

--------------------------------

[ Upstream commit 12d572e7 ]

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: NMasami Hiramatsu <mhiramat@kernel.org>
Reviewed-by: NSrikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: stable@vger.kernel.org
Link: http://lore.kernel.org/lkml/159438668346.62703.10887420400718492503.stgit@devnote2Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 bd9f5915
...@@ -1357,7 +1357,7 @@ int debuginfo__find_trace_events(struct debuginfo *dbg, ...@@ -1357,7 +1357,7 @@ int debuginfo__find_trace_events(struct debuginfo *dbg,
tf.ntevs = 0; tf.ntevs = 0;
ret = debuginfo__find_probes(dbg, &tf.pf); ret = debuginfo__find_probes(dbg, &tf.pf);
if (ret < 0) { if (ret < 0 || tf.ntevs == 0) {
for (i = 0; i < tf.ntevs; i++) for (i = 0; i < tf.ntevs; i++)
clear_probe_trace_event(&tf.tevs[i]); clear_probe_trace_event(&tf.tevs[i]);
zfree(tevs); zfree(tevs);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册