aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2024-04-29 16:17:16 -0700
committerAndrii Nakryiko <andrii@kernel.org>2024-04-29 16:17:16 -0700
commit789d9a53d2f633317c64de3eba0940f31a8f0cd6 (patch)
treef4e0204c8bf1d4b7ca95c274c723c5fe18e82bf1
parent19468ed51488dae19254e8a67c75d583b05fa5e3 (diff)
parent25927d0a1bec5091d371693c9fdd9640478837de (diff)
Merge branch 'free-strdup-memory-in-selftests'
Geliang Tang says: ==================== Free strdup memory in selftests From: Geliang Tang <tanggeliang@kylinos.cn> Two fixes to free strdup memory in selftests to avoid memory leaks. ==================== Link: https://lore.kernel.org/r/cover.1714374022.git.tanggeliang@kylinos.cn Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
-rw-r--r--tools/testing/selftests/bpf/test_sockmap.c10
-rw-r--r--tools/testing/selftests/bpf/veristat.c5
2 files changed, 12 insertions, 3 deletions
diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
index 43612de44fbf..92752f5eeded 100644
--- a/tools/testing/selftests/bpf/test_sockmap.c
+++ b/tools/testing/selftests/bpf/test_sockmap.c
@@ -1887,10 +1887,13 @@ static int check_whitelist(struct _test *t, struct sockmap_options *opt)
while (entry) {
if ((opt->prepend && strstr(opt->prepend, entry) != 0) ||
strstr(opt->map, entry) != 0 ||
- strstr(t->title, entry) != 0)
+ strstr(t->title, entry) != 0) {
+ free(ptr);
return 0;
+ }
entry = strtok(NULL, ",");
}
+ free(ptr);
return -EINVAL;
}
@@ -1907,10 +1910,13 @@ static int check_blacklist(struct _test *t, struct sockmap_options *opt)
while (entry) {
if ((opt->prepend && strstr(opt->prepend, entry) != 0) ||
strstr(opt->map, entry) != 0 ||
- strstr(t->title, entry) != 0)
+ strstr(t->title, entry) != 0) {
+ free(ptr);
return 0;
+ }
entry = strtok(NULL, ",");
}
+ free(ptr);
return -EINVAL;
}
diff --git a/tools/testing/selftests/bpf/veristat.c b/tools/testing/selftests/bpf/veristat.c
index 244d4996e06e..b2854238d4a0 100644
--- a/tools/testing/selftests/bpf/veristat.c
+++ b/tools/testing/selftests/bpf/veristat.c
@@ -792,10 +792,13 @@ static int parse_stats(const char *stats_str, struct stat_specs *specs)
while ((next = strtok_r(state ? NULL : input, ",", &state))) {
err = parse_stat(next, specs);
- if (err)
+ if (err) {
+ free(input);
return err;
+ }
}
+ free(input);
return 0;
}