Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752634AbbKKOp0 (ORCPT ); Wed, 11 Nov 2015 09:45:26 -0500 Received: from mail7.hitachi.co.jp ([133.145.228.42]:56358 "EHLO mail7.hitachi.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752525AbbKKOpZ (ORCPT ); Wed, 11 Nov 2015 09:45:25 -0500 X-AuditID: 85900ec0-9b9c6b9000001a57-81-564352e3115d Subject: [PATCH perf/core ] [BUGFIX] perf probe: Fix memory leaking on faiulre by clearing all probe_trace_events From: Masami Hiramatsu To: linux-kernel@vger.kernel.org Cc: Arnaldo Carvalho de Melo , Wang Nan , Zefan Li , pi3orama@163.com Date: Wed, 11 Nov 2015 23:38:23 +0900 Message-ID: <20151111143823.6275.73467.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1614 Lines: 43 Fix memory leaking on failure path in debuginfo__find_trace_events() which frees an array of probe_trace_events but doesn't clear all allocated sub-structures and strings. So, before doing zfree(tevs), clear all the array elements which can have allocated resources. Signed-off-by: Masami Hiramatsu Reported-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Zefan Li Cc: pi3orama@163.com --- tools/perf/util/probe-finder.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index bd8f03d..63993d7 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -1246,7 +1246,7 @@ int debuginfo__find_trace_events(struct debuginfo *dbg, struct trace_event_finder tf = { .pf = {.pev = pev, .callback = add_probe_trace_event}, .max_tevs = probe_conf.max_probes, .mod = dbg->mod}; - int ret; + int ret, i; /* Allocate result tevs array */ *tevs = zalloc(sizeof(struct probe_trace_event) * tf.max_tevs); @@ -1258,6 +1258,8 @@ int debuginfo__find_trace_events(struct debuginfo *dbg, ret = debuginfo__find_probes(dbg, &tf.pf); if (ret < 0) { + for (i = 0; i < tf.ntevs; i++) + clear_probe_trace_event(&tf.tevs[i]); zfree(tevs); return ret; } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/