From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF818C433DF for ; Thu, 9 Jul 2020 08:07:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C297E20720 for ; Thu, 9 Jul 2020 08:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594282049; bh=3+FvW+XUZpDxlr9KNw5KrcNgNb9DwKwajaCToySNN8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lkt7jC6KKUZYtxd9vH15B+gU+eCMHNtX2jcER4LjLwKp07rQVLkDve3jVmE9ohZYp KRcXXVqa1QpYNjaJJQymhXzM4uq9F0Vrpk+/qzWZfmc4jVoj/9QTe0RyLViHlf7Biw Kr1RjIHOuUA/rXOPPlPp0wkzNa4bNKrtwKMFSZCU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726387AbgGIIH2 (ORCPT ); Thu, 9 Jul 2020 04:07:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:58654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726139AbgGIIH0 (ORCPT ); Thu, 9 Jul 2020 04:07:26 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 53E7220720; Thu, 9 Jul 2020 08:07:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594282046; bh=3+FvW+XUZpDxlr9KNw5KrcNgNb9DwKwajaCToySNN8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wXQ44iQ6rdOTpk/S7WXrZBrl9AU7A5eiXkIk/0j2BGG+5vFzlxmS14ejMgry9BcUP dGqHgnBmxMADxOdM9tjEaS3IK5Yvm3w5b57xJHERJfZLeuOHBDiTfU56INav9O/l30 h+f8mVgGpNX9I5ZLXrG6idy/bc0JRi3/qp0fprwQ= From: Masami Hiramatsu To: Arnaldo Carvalho de Melo , Arnaldo Carvalho de Melo Cc: Oleg Nesterov , Srikar Dronamraju , linux-kernel@vger.kernel.org, mhiramat@kernel.org, Andi Kleen , Andi Kleen Subject: [PATCH 3/4] perf-probe: Fix memory leakage when the probe point is not found Date: Thu, 9 Jul 2020 17:07:22 +0900 Message-Id: <159428204201.56570.8191554031198604445.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <159428201109.56570.3802208017109058146.stgit@devnote2> References: <159428201109.56570.3802208017109058146.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: ff741783506c ("perf probe: Introduce debuginfo to encapsulate dwarf information") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu --- tools/perf/util/probe-finder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 9963e4e8ea20..659024342e9a 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -1467,7 +1467,7 @@ int debuginfo__find_trace_events(struct debuginfo *dbg, if (ret >= 0 && tf.pf.skip_empty_arg) ret = fill_empty_trace_arg(pev, tf.tevs, tf.ntevs); - if (ret < 0) { + if (ret < 0 || tf.ntevs == 0) { for (i = 0; i < tf.ntevs; i++) clear_probe_trace_event(&tf.tevs[i]); zfree(tevs);