All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gokul K <gokul02k@gmail.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org
Cc: Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org, Peter Gonda <pgonda@google.com>,
	Jing Zhang <jingzhangos@google.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] KVM: selftests: Free the stats id string when no stats are defined
Date: Tue,  1 Dec 2026 14:36:32 +0530	[thread overview]
Message-ID: <20261201090632.2482795-4-gokul02k@gmail.com> (raw)
In-Reply-To: <20261201090632.2482795-1-gokul02k@gmail.com>

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@gmail.com>
---
 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



  parent reply	other threads:[~2026-12-01  9:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  9:06 [PATCH 0/3] KVM: selftests: Fix three leaked resources Gokul K
2026-12-01  9:06 ` [PATCH 1/3] KVM: selftests: Close /dev/sev when an SEV VM is released Gokul K
2026-12-01  9:06 ` [PATCH 2/3] KVM: selftests: Close the SEV fd opened for each KVM_SEV_INIT2 ioctl Gokul K
2026-12-01  9:06 ` Gokul K [this message]
2026-12-01  9:12   ` [PATCH 3/3] KVM: selftests: Free the stats id string when no stats are defined sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201090632.2482795-4-gokul02k@gmail.com \
    --to=gokul02k@gmail.com \
    --cc=jingzhangos@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=pgonda@google.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.