Commit f25d5416 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

selftests/bpf: Fix memory leak in test selector

Free test selector substrings, which were strdup()'ed.

Fixes: b65053cd ("selftests/bpf: Add whitelist/blacklist of test names to test_progs")
Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200429012111.277390-6-andriin@fb.com
parent 229bf8bf
...@@ -420,6 +420,18 @@ static int libbpf_print_fn(enum libbpf_print_level level, ...@@ -420,6 +420,18 @@ static int libbpf_print_fn(enum libbpf_print_level level,
return 0; return 0;
} }
static void free_str_set(const struct str_set *set)
{
int i;
if (!set)
return;
for (i = 0; i < set->cnt; i++)
free((void *)set->strs[i]);
free(set->strs);
}
static int parse_str_list(const char *s, struct str_set *set) static int parse_str_list(const char *s, struct str_set *set)
{ {
char *input, *state = NULL, *next, **tmp, **strs = NULL; char *input, *state = NULL, *next, **tmp, **strs = NULL;
...@@ -756,11 +768,11 @@ int main(int argc, char **argv) ...@@ -756,11 +768,11 @@ int main(int argc, char **argv)
fprintf(stdout, "Summary: %d/%d PASSED, %d SKIPPED, %d FAILED\n", fprintf(stdout, "Summary: %d/%d PASSED, %d SKIPPED, %d FAILED\n",
env.succ_cnt, env.sub_succ_cnt, env.skip_cnt, env.fail_cnt); env.succ_cnt, env.sub_succ_cnt, env.skip_cnt, env.fail_cnt);
free(env.test_selector.blacklist.strs); free_str_set(&env.test_selector.blacklist);
free(env.test_selector.whitelist.strs); free_str_set(&env.test_selector.whitelist);
free(env.test_selector.num_set); free(env.test_selector.num_set);
free(env.subtest_selector.blacklist.strs); free_str_set(&env.subtest_selector.blacklist);
free(env.subtest_selector.whitelist.strs); free_str_set(&env.subtest_selector.whitelist);
free(env.subtest_selector.num_set); free(env.subtest_selector.num_set);
return env.fail_cnt ? EXIT_FAILURE : EXIT_SUCCESS; return env.fail_cnt ? EXIT_FAILURE : EXIT_SUCCESS;
......
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