Commit eb7261f1 authored by Riccardo Mancini's avatar Riccardo Mancini Committed by Arnaldo Carvalho de Melo

perf test: Add free() calls for scandir() returned dirent entries

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: da963834 ("perf test: Iterate over shell tests in alphabetical order")
Signed-off-by: default avatarRiccardo Mancini <rickyman7@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Remi Bernon <rbernon@codeweavers.com>
Link: http://lore.kernel.org/lkml/20210709163454.672082-1-rickyman7@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent afd4ad01
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/string.h> #include <linux/string.h>
#include <subcmd/exec-cmd.h> #include <subcmd/exec-cmd.h>
#include <linux/zalloc.h>
static bool dont_fork; static bool dont_fork;
...@@ -540,7 +541,7 @@ static int shell_tests__max_desc_width(void) ...@@ -540,7 +541,7 @@ static int shell_tests__max_desc_width(void)
{ {
struct dirent **entlist; struct dirent **entlist;
struct dirent *ent; struct dirent *ent;
int n_dirs; int n_dirs, e;
char path_dir[PATH_MAX]; char path_dir[PATH_MAX];
const char *path = shell_tests__dir(path_dir, sizeof(path_dir)); const char *path = shell_tests__dir(path_dir, sizeof(path_dir));
int width = 0; int width = 0;
...@@ -564,8 +565,9 @@ static int shell_tests__max_desc_width(void) ...@@ -564,8 +565,9 @@ static int shell_tests__max_desc_width(void)
} }
} }
for (e = 0; e < n_dirs; e++)
zfree(&entlist[e]);
free(entlist); free(entlist);
return width; return width;
} }
...@@ -596,7 +598,7 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width) ...@@ -596,7 +598,7 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width)
{ {
struct dirent **entlist; struct dirent **entlist;
struct dirent *ent; struct dirent *ent;
int n_dirs; int n_dirs, e;
char path_dir[PATH_MAX]; char path_dir[PATH_MAX];
struct shell_test st = { struct shell_test st = {
.dir = shell_tests__dir(path_dir, sizeof(path_dir)), .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) ...@@ -629,6 +631,8 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width)
test_and_print(&test, false, -1); test_and_print(&test, false, -1);
} }
for (e = 0; e < n_dirs; e++)
zfree(&entlist[e]);
free(entlist); free(entlist);
return 0; return 0;
} }
...@@ -730,7 +734,7 @@ static int perf_test__list_shell(int argc, const char **argv, int i) ...@@ -730,7 +734,7 @@ static int perf_test__list_shell(int argc, const char **argv, int i)
{ {
struct dirent **entlist; struct dirent **entlist;
struct dirent *ent; struct dirent *ent;
int n_dirs; int n_dirs, e;
char path_dir[PATH_MAX]; char path_dir[PATH_MAX];
const char *path = shell_tests__dir(path_dir, sizeof(path_dir)); 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) ...@@ -752,8 +756,11 @@ static int perf_test__list_shell(int argc, const char **argv, int i)
continue; continue;
pr_info("%2d: %s\n", i, t.desc); pr_info("%2d: %s\n", i, t.desc);
} }
for (e = 0; e < n_dirs; e++)
zfree(&entlist[e]);
free(entlist); free(entlist);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment