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=-13.1 required=3.0 tests=BAYES_00,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=unavailable 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 46DFEC433DF for ; Fri, 10 Jul 2020 13:11:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2353A2078D for ; Fri, 10 Jul 2020 13:11:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594386691; bh=C69RMc7t7guHcL8gGCtB5Yz+90nRiphCbSaewJtAEx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iBr7Dor2uTtGuIwc7q84ig4GVPEpGl9wQq5EdIztKu3dkaQoMr2aC1j6cmi/j51Z4 ULqdOmRXkCra2vNulFqAvOnFX1dc+Jam2zhTScB5Uov257jFAKqgQJvOlDssLeFaqp THY/3gcs8NqLno4Lsbmc/uH5hVDQEabv6PRfwQMM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728043AbgGJNL3 (ORCPT ); Fri, 10 Jul 2020 09:11:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:49626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727074AbgGJNL2 (ORCPT ); Fri, 10 Jul 2020 09:11:28 -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 E69A52077D; Fri, 10 Jul 2020 13:11:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594386688; bh=C69RMc7t7guHcL8gGCtB5Yz+90nRiphCbSaewJtAEx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FXCnfgN969rGm3NzjCjYAWKQVUN1/ZxuaLc64AxHfmLchZzkRWNWj5tnEsnOnGxZM dJl5nvtdFi0uP+2kjhLyxwiK00nQB+N4p7D3CCq7xyCS5TahQJQPnlTyup5ZpYTQ1r 4Sb6WRNkBslA4y94ZVsE3cplkC3yoNNr9Pkp48Nw= 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 v2 3/4] perf-probe: Fix memory leakage when the probe point is not found Date: Fri, 10 Jul 2020 22:11:23 +0900 Message-Id: <159438668346.62703.10887420400718492503.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <159438665389.62703.13848613271334658629.stgit@devnote2> References: <159438665389.62703.13848613271334658629.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 Reviewed-by: Srikar Dronamraju --- 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);