Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2894225rwr; Fri, 28 Apr 2023 18:59:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5aeIorf9bkBiYOjPBLu6YGdeQJvHHDaA1Flvzcuv+zngMzZ6UgvE38sWpz5fKM58AzcM3t X-Received: by 2002:a05:6a20:8e19:b0:f2:fe5a:d471 with SMTP id y25-20020a056a208e1900b000f2fe5ad471mr7082960pzj.5.1682733550346; Fri, 28 Apr 2023 18:59:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682733550; cv=none; d=google.com; s=arc-20160816; b=z0osARK/XZE2wDuEZjYj8et8GsmoFnl5UYdhMUH6AUMZYfnilQcTE4gMscx10aBkvx QDmQOht5Y0AdiaT3eRx9WdD9WRES62HkkK+iuh+wtJrXIuyTDnj4+cJaiyRBwGUwgyNW dtfjeQh8PDDWo0+rr7o8+0zdoD7DfCklst/amETkQgnfxYVzGTfij5syv0YxjM84IjfS DhZgnK/VqOrRNeRMPt87pQRuR+zzLvFrRCCzu6Xe1gG2SwH3kvz2E/Rg3zyVls1yPu/x GFyQxnV3ZAtOZNyiy9yhrq5Ihh9qF5cdOXkhBdjQaLszS8Dit/3heofjsO+ZnZK8tGG+ 1O8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=3i7v7/hElTOeG72oCF9Ci5giMydtfWzZht9sCeb/D48=; b=ax3fNeCJYAL7L2A1XML+KUUY0hhndeoH/3d3CzdFivd9F+RRmZ/na5Y4zOrlJbvQc2 eNol++wDLPChpsDAn5U4YVVv9Dp2EOPFsH4xicR1KKFe88PW9fv9rO1ir3L1QWpJVX3N EP6ZW3aX9WlqTcMz/Zyno4h6hfrNa9bhyDegIbFGl9w/j2744bJTXsn9N+0XsM00fCDl tGRE+BtRoN8HGt9IBMP6pzhJI8F09DzJlmbMv9nKX7/dVxhYsQ06gGFqUIINXNmTrQVF QzV2V+8y0ZX8yAU5iuhmIC4OQXRLgujFkOsgb57yqQNfrb/qs+F6CZy+NS9Cv0P3zT2h O5sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VruZ9vwo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h70-20020a638349000000b005254580c66bsi15963587pge.231.2023.04.28.18.58.59; Fri, 28 Apr 2023 18:59:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VruZ9vwo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347263AbjD2BaK (ORCPT + 99 others); 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 X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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