Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp814700pxv; Fri, 9 Jul 2021 09:37:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk88L54h4/8YVFVaWlaDZjaVyCPpxMgrocKamR9MWghiMbG4GKSzV0pRTICj3NcZQiJSbl X-Received: by 2002:a05:6602:d9:: with SMTP id z25mr7214657ioe.154.1625848651930; Fri, 09 Jul 2021 09:37:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625848651; cv=none; d=google.com; s=arc-20160816; b=dv/r0It87Lp0zbWk0dM3K/8qN6xXmm0sTQSnH5TGHnbrJiFJUqYuOa6a5CwBPCsKR3 ExRCzJv49gDsotmfc6rn37m2jtP7rKiZwNdvBJIqry82MNWj3zabZ0HD6bfoa6olKFlC 6g2Efj/ET7tZ+LJJRLmwnmZLaUV6x7ZrJmztNNSzxhcwUns7ExAExwBZZUo/Os9sU2Lo El76sNIJjY4ggJAqT80GcdckWKCaE28X3eP3h0NkbjVG1LWkBOhFTBwbTSW45qi2l+JE lYmKc0oHRYp+NEwEwn8mwIUaXib2mlvxhQ/LEpjrS62vekca3LMBYYxTOXSLAr/BzDEM HA2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=tQVonobh9dEWViCupkTvvzo+E7fxVjP7o2OOWiVB+Hw=; b=z5qhiS65O7Q87aNy0HNnWMBJbDLVRVMN0N0PXmVts+zvQeTcoe87FsdCJXDsBfVqxe h7hvp2Gtq2fiCE8bKpWrUBNe1mOAynHKrnzJWu5P+PrWQK/EVeKK+JT2/EvnzNdlj5BU f6X983X0uQ3sksZroCscwuJssLolrHerMoQC3p906SQvXNgo9bbj3imlypJ7alfadhhy I+975L7AlCWIjsxLkLkWPrtIKMkqZIordm/JMR3orVaR9qxcvqYUvCAWix7nvNZFMP8l u0qHqWnhybqgWrL9sDnG83/uxtmRyQpIkmgqQP1hm1uFgfYzi1u/QVcgBYJnmyuPsppP X/aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AHXL2iVj; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si7130833ilh.139.2021.07.09.09.37.19; Fri, 09 Jul 2021 09:37:31 -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=@gmail.com header.s=20161025 header.b=AHXL2iVj; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229535AbhGIQh4 (ORCPT + 99 others); Fri, 9 Jul 2021 12:37:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbhGIQh4 (ORCPT ); Fri, 9 Jul 2021 12:37:56 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E49EBC0613DD; Fri, 9 Jul 2021 09:35:11 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id h8so1419401eds.4; Fri, 09 Jul 2021 09:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tQVonobh9dEWViCupkTvvzo+E7fxVjP7o2OOWiVB+Hw=; b=AHXL2iVjVJS4yxCtwy4e+Z6lbW8mAqOYVFO1kOuzbR31sEFXPAGUQM6yRV4G44Cp6I WmY9Vp9SFuoJvulaX6X2cxh7iWWx5lDEXUu0aZZSE4F7F1F5mjq/+0AxpNjfPqTBDtcx 4guH7Hl80pHp7fBk5WsPjnpE+uE//33Oh7rKEwSYOlv+ktRJUvtvM/Nai3CMiwr+nntu crawwmaySoGLFkAPJ7DCHDm1VD4qTNffJ5hgOMzRCYadVIdykQVuy7aVCWREib2rJkUd poTOFnYU8OneJVyZ1awUO4Fu1oKF9twnO1Mr1kaR/iRRAwSl3eeuh9XvkHL/bgL1NO06 uNrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tQVonobh9dEWViCupkTvvzo+E7fxVjP7o2OOWiVB+Hw=; b=dIpDxglM1ENkHaU9YleG6Xh0O0qSFKdksIw7N7oUv6SVVt2KbOGm9RNNFXMT9nM133 vAd1P6UFr893KyTuOJPn/6poE7VolpJtEOd/mzHcT00wrffiKNLwtxTAszulL039oRJ9 R2fL44fpJNU1LMr696vg5IjQymRx4JfzhdrKDZlWqtxLeZzqU5piC/0QTZdIFkn3fPKS a7laSBeDP+E+A1PL1yQXxy2t1aWYz5bN7+uS61G5kNsoIDGyB1Np1xmd8i9ECw6EcVqy Kk5WxUtbUTOqCez5kmBUXUiXWtqHmcdJMAkecyKAB3QwfacGdEfVk88Si2jF42ybDyki 2bXw== X-Gm-Message-State: AOAM532Px7lBAAque7cS9Yr9heIhVVj1/2mjOOzjw70jVVw958uPqdO6 mm9zMj0rslOM8tXjLCFThGc= X-Received: by 2002:a05:6402:50d3:: with SMTP id h19mr37507219edb.344.1625848509907; Fri, 09 Jul 2021 09:35:09 -0700 (PDT) Received: from honeypot.lan ([2001:b07:6456:fd99:ced0:db1c:53e1:191e]) by smtp.googlemail.com with ESMTPSA id b25sm3341899edv.9.2021.07.09.09.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 09:35:09 -0700 (PDT) From: Riccardo Mancini To: Arnaldo Carvalho de Melo Cc: Namhyung Kim , Ian Rogers , Riccardo Mancini , 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: [PATCH] perf test: add missing free for scandir-returned dirent entities Date: Fri, 9 Jul 2021 18:34:53 +0200 Message-Id: <20210709163454.672082-1-rickyman7@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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