Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp888142pxv; Fri, 9 Jul 2021 11:22:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhF3hcWvp6OUB5NC5jePBXelby6wS9Yl2Gc9b0QC2ficiaqekbocOO1SHjJfARNwvhMuAI X-Received: by 2002:a05:6e02:78c:: with SMTP id q12mr15291935ils.243.1625854950687; Fri, 09 Jul 2021 11:22:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625854950; cv=none; d=google.com; s=arc-20160816; b=oFO9OaEtBq6L4msJMowGc/42QiHREs38gnaj4h9rMDGpYxwahHh4b5digIlAdXwEXJ hLm+CbF9DhpWCmYDU7uVxPnarVh+y533OIn2a7lgTkWZMYV7p6W+rbFLPFMdcfmodWAM PGWQZGFCL6on5/0O/+MQy+lESa73iWHfzow9U472/OUAAcb7nJoCD85INRL2naLY4sXk 4DS6cC/HKHy3juqRob13kkq40n9f35wx8+DT8z0Zy3uu7pXsnhyrgaEf1Ztx3FV9xKeg 7jcXUsybJraXwQDIbxeML9M5Gzlhw1OK7YfqJIPkNlIy/vn3YIme/aksbFkJPCKNj1dO P+BA== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bqiZreQY7eV2y4KwsBUT9bGFas9gdNsm7OqEE1QCHvE=; b=yrG9y7cqNjjcKYW0kxul+xO/dPXX5EntC//ixqBjdRveDpumUb4WxcTzUW0Ry+uo8T OLUwWJRS7OvXCC4bZRWM11cN0Rb4fwkLnp36bcmVOFt0x76mpsKsUcN9MuvlJjb1r1i8 htD+CU1WvAB6YyxYp7KzQJhLmczksF6Vx8MqDemprhE/44pPKpozIhSwE8KmIXxvVOnP ykZZZk7CJUGPilgJaMghWRqG7X5Rl+IVn+YO2GnRL/bDlejDBKwMf7WZkRfW7K/IlrSH tC8Qm2uHiZih4v8fysVayQvKoYE4hKHAV9VgXvaV0yhztbx/IjBcPwXs1p3W4+bABxZ0 JDzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="N/HLJC2q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x22si6882923iow.99.2021.07.09.11.22.18; Fri, 09 Jul 2021 11:22:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="N/HLJC2q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229546AbhGISYe (ORCPT + 99 others); Fri, 9 Jul 2021 14:24:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:47070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbhGISYe (ORCPT ); Fri, 9 Jul 2021 14:24:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 44A0061361; Fri, 9 Jul 2021 18:21:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625854910; bh=eKI2MKP/0FuOgp2lSQADbh4/n7CDz5nAGAOBVI4TIjo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=N/HLJC2qL9tBRINagovny6irxRVUrUF93KF4dCITFUitVY/jhT/JVsjNuAarTWWst dElW6tywW5jWecoyYIPhIHM+Ok8n60VlMkOV+JbMcfrJja3A5iktp3xNb1ZmMxJWeY dW14BVXdmyWY682mZb1gAGCVUQGu8vOeUmmQbPEYoUXdv21LF9qRV5S/qWMYRAq+f1 3yp0U9ADUMQNcgZGCEOtZNYeuDlXC+9vLlux8tp1JrTvUMsyqjl2k8je8pY6YC7Ot5 vy8IzwAV2c1JeXqSDGovhzofv3vUkOeZrB/xKr+6mPsEIJuxxzNUd1HGZwd7MgVXZP O0tFc62E6XTbw== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 0512940B1A; Fri, 9 Jul 2021 15:21:46 -0300 (-03) Date: Fri, 9 Jul 2021 15:21:46 -0300 From: Arnaldo Carvalho de Melo To: Riccardo Mancini Cc: Namhyung Kim , Ian Rogers , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Leo Yan , Remi Bernon , Fabian Hemmer , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf test: add missing free for scandir-returned dirent entities Message-ID: References: <20210709163454.672082-1-rickyman7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210709163454.672082-1-rickyman7@gmail.com> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Jul 09, 2021 at 06:34:53PM +0200, Riccardo Mancini escreveu: > ASan reported a memory leak for items of the entlist returned from scandir. > In fact, scandir returns a malloc'd array of malloc'd dirents. > This patch adds the missing (z)frees. Hey, I thought you were pluging old leaks, this one was introduced recently ;-) :-) Thanks, applied! - Arnaldo > Fixes: da963834fe6975a1 ("perf test: Iterate over shell tests in alphabetical order") > Signed-off-by: Riccardo Mancini > --- > tools/perf/tests/builtin-test.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c > index 41e3cf6bb66c68e8..5e6242576236325c 100644 > --- a/tools/perf/tests/builtin-test.c > +++ b/tools/perf/tests/builtin-test.c > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > > static bool dont_fork; > > @@ -540,7 +541,7 @@ static int shell_tests__max_desc_width(void) > { > struct dirent **entlist; > struct dirent *ent; > - int n_dirs; > + int n_dirs, e; > char path_dir[PATH_MAX]; > const char *path = shell_tests__dir(path_dir, sizeof(path_dir)); > int width = 0; > @@ -564,8 +565,9 @@ static int shell_tests__max_desc_width(void) > } > } > > + for (e = 0; e < n_dirs; e++) > + zfree(&entlist[e]); > free(entlist); > - > return width; > } > > @@ -596,7 +598,7 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width) > { > struct dirent **entlist; > struct dirent *ent; > - int n_dirs; > + int n_dirs, e; > char path_dir[PATH_MAX]; > struct shell_test st = { > .dir = shell_tests__dir(path_dir, sizeof(path_dir)), > @@ -629,6 +631,8 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width) > test_and_print(&test, false, -1); > } > > + for (e = 0; e < n_dirs; e++) > + zfree(&entlist[e]); > free(entlist); > return 0; > } > @@ -730,7 +734,7 @@ static int perf_test__list_shell(int argc, const char **argv, int i) > { > struct dirent **entlist; > struct dirent *ent; > - int n_dirs; > + int n_dirs, e; > char path_dir[PATH_MAX]; > const char *path = shell_tests__dir(path_dir, sizeof(path_dir)); > > @@ -752,8 +756,11 @@ static int perf_test__list_shell(int argc, const char **argv, int i) > continue; > > pr_info("%2d: %s\n", i, t.desc); > + > } > > + for (e = 0; e < n_dirs; e++) > + zfree(&entlist[e]); > free(entlist); > return 0; > } > -- > 2.23.0 > -- - Arnaldo