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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D12AC77B60 for ; Sat, 29 Apr 2023 01:30:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347152AbjD2BaK (ORCPT ); Fri, 28 Apr 2023 21:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230338AbjD2BaH (ORCPT ); Fri, 28 Apr 2023 21:30:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08A00E7A; Fri, 28 Apr 2023 18:30:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5A96F61592; Sat, 29 Apr 2023 01:30:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83C46C4339B; Sat, 29 Apr 2023 01:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682731804; bh=H1cUVZloMIMgPmyVATWNTj1bXJbmgcmWRMx4csgzg9s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VruZ9vwomrjap0GaYFrqDzIJX9CjBi7wGIWNr+9ZNlTauB7K3vwwL698PvA2nQvVg XRt5btcIG4aWmkRxtGYqHJuzO/xuXZTlWxCkq0SXWIcd59qWS254KsYQmP2LTx9d3R 1J05jNZIpioTdJr7eH4rULGzKVOR1ph5PBfKfa6SqoGLYbbYX3aSm6CngFqT38ZvzF oW65Q49XxT+GiZ3cI7FdXGjtxkiLJ31OCaf5jkf4o1R7Fq0mEY+OgYAihE+r9/OdvB Gx1gB9Nd47GiHC8jspgk1b0BTj6HI4wfZZjxIgN3+isunZuyfX6LOcqwzoCfGgI/tx jbw9Y+NoUUswA== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id BA120403B5; Fri, 28 Apr 2023 22:30:01 -0300 (-03) Date: Fri, 28 Apr 2023 22:30:01 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Namhyung Kim , Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: Re: [PATCH 1/2] perf list: Fix memory leaks in print_tracepoint_events() Message-ID: References: <20230427230502.1526136-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Em Thu, Apr 27, 2023 at 05:27:50PM -0700, Ian Rogers escreveu: > On Thu, Apr 27, 2023 at 4:05 PM Namhyung Kim wrote: > > > > It should free entries (not only the array) filled by scandirat() > > after use. > > > > Signed-off-by: Namhyung Kim > > Reviewed-by: Ian Rogers Thanks, applied the series. - Arnaldo > Thanks, > Ian > > > --- > > tools/perf/util/print-events.c | 12 ++++++++---- > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c > > index d416c5484cd5..0a97912fd894 100644 > > --- a/tools/perf/util/print-events.c > > +++ b/tools/perf/util/print-events.c > > @@ -83,11 +83,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus > > if (sys_dirent->d_type != DT_DIR || > > !strcmp(sys_dirent->d_name, ".") || > > !strcmp(sys_dirent->d_name, "..")) > > - continue; > > + goto next_sys; > > > > dir_fd = openat(events_fd, sys_dirent->d_name, O_PATH); > > if (dir_fd < 0) > > - continue; > > + goto next_sys; > > > > evt_items = scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NULL, alphasort); > > for (int j = 0; j < evt_items; j++) { > > @@ -98,12 +98,12 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus > > if (evt_dirent->d_type != DT_DIR || > > !strcmp(evt_dirent->d_name, ".") || > > !strcmp(evt_dirent->d_name, "..")) > > - continue; > > + goto next_evt; > > > > snprintf(evt_path, sizeof(evt_path), "%s/id", evt_dirent->d_name); > > evt_fd = openat(dir_fd, evt_path, O_RDONLY); > > if (evt_fd < 0) > > - continue; > > + goto next_evt; > > close(evt_fd); > > > > snprintf(evt_path, MAXPATHLEN, "%s:%s", > > @@ -119,9 +119,13 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus > > /*desc=*/NULL, > > /*long_desc=*/NULL, > > /*encoding_desc=*/NULL); > > +next_evt: > > + free(evt_namelist[j]); > > } > > close(dir_fd); > > free(evt_namelist); > > +next_sys: > > + free(sys_namelist[i]); > > } > > > > free(sys_namelist); > > -- > > 2.40.1.495.gc816e09b53d-goog > > -- - Arnaldo