[PATCH 3/3] KVM: selftests: Free the stats id string when no stats are defined
From: Gokul K
Date: Tue Dec 01 2026 - 04:07:17 EST
stats_test() allocates the id string before it sanity checks the header,
then returns early if the kernel reports no stats descriptors. The normal
path frees id along with stats_desc and stats_data, but this return does
not, so the allocation is lost.
A goto would be wrong here: stats_desc and stats_data are still
uninitialised at this point, and the common exit path frees both. Free the
one live allocation instead.
Fixes: 0b45d58738cd ("KVM: selftests: Add selftest for KVM statistics data binary interface")
Signed-off-by: Gokul K <gokul02k@xxxxxxxxx>
---
tools/testing/selftests/kvm/kvm_binary_stats_test.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/kvm/kvm_binary_stats_test.c b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
index b7dbde9c0843..89ae011ffae9 100644
--- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c
+++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
@@ -53,6 +53,7 @@ static void stats_test(int stats_fd)
/* Sanity check for other fields in header */
if (header.num_desc == 0) {
ksft_print_msg("No KVM stats defined!\n");
+ free(id);
return;
}
/*
--
2.54.0