diff options
| author | Feng Yang <yangfeng@kylinos.cn> | 2026-07-23 16:51:00 +0800 |
|---|---|---|
| committer | Kumar Kartikeya Dwivedi <memxor@gmail.com> | 2026-07-24 23:15:21 +0200 |
| commit | 06efb01c6530e9cfc247178cb96aa8adb3beaf61 (patch) | |
| tree | da2adc1219ac4013e2d397cbd62377559074b6b9 | |
| parent | a813ad2185cd9f653a79b96b7c8a24240118c4e1 (diff) | |
| download | linux-06efb01c6530e9cfc247178cb96aa8adb3beaf61.tar.gz linux-06efb01c6530e9cfc247178cb96aa8adb3beaf61.zip | |
selftests/bpf: Fix memory leak on subtest_states reallocation
Fix memory leak in subtest_states reallocation,
and revert subtest_num if allocation fails.
Fixes: 0925225956bb ("bpf/selftests: Add granular subtest output for prog_test")
Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
Link: https://lore.kernel.org/bpf/20260723085100.482147-6-yangfeng59949@163.com
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
| -rw-r--r-- | tools/testing/selftests/bpf/test_progs.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c index 07da45230c4b..aa06bab30966 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -573,18 +573,19 @@ bool test__start_subtest_with_desc(const char *subtest_name, const char *subtest struct subtest_state *subtest_state; const char *subtest_display_name; size_t sub_state_size = sizeof(*subtest_state); + void *tmp; if (env.subtest_state) test__end_subtest(); state->subtest_num++; - state->subtest_states = - realloc(state->subtest_states, - state->subtest_num * sub_state_size); - if (!state->subtest_states) { + tmp = realloc(state->subtest_states, state->subtest_num * sub_state_size); + if (!tmp) { + state->subtest_num--; fprintf(stderr, "Not enough memory to allocate subtest result\n"); return false; } + state->subtest_states = tmp; subtest_state = &state->subtest_states[state->subtest_num - 1]; |
