[PATCH 1/2] i386/kvm/vmsr_energy: Plug memory leak on failure to connect socket

Markus Armbruster posted 2 patches 3 months, 3 weeks ago
Maintainers: John Levon <john.levon@nutanix.com>, Thanos Makatos <thanos.makatos@nutanix.com>, "Cédric Le Goater" <clg@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>, Marcelo Tosatti <mtosatti@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>
[PATCH 1/2] i386/kvm/vmsr_energy: Plug memory leak on failure to connect socket
Posted by Markus Armbruster 3 months, 3 weeks ago
vmsr_open_socket() leaks the Error set by
qio_channel_socket_connect_sync().  Plug the leak by not creating the
Error.

Fixes: 0418f90809ae (Add support for RAPL MSRs in KVM/Qemu)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 target/i386/kvm/vmsr_energy.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/target/i386/kvm/vmsr_energy.c b/target/i386/kvm/vmsr_energy.c
index 58ce3df53a..890322ae37 100644
--- a/target/i386/kvm/vmsr_energy.c
+++ b/target/i386/kvm/vmsr_energy.c
@@ -57,13 +57,9 @@ QIOChannelSocket *vmsr_open_socket(const char *path)
     };
 
     QIOChannelSocket *sioc = qio_channel_socket_new();
-    Error *local_err = NULL;
 
     qio_channel_set_name(QIO_CHANNEL(sioc), "vmsr-helper");
-    qio_channel_socket_connect_sync(sioc,
-                                    &saddr,
-                                    &local_err);
-    if (local_err) {
+    if (qio_channel_socket_connect_sync(sioc, &saddr, NULL) < 0) {
         /* Close socket. */
         qio_channel_close(QIO_CHANNEL(sioc), NULL);
         object_unref(OBJECT(sioc));
-- 
2.49.0
Re: [PATCH 1/2] i386/kvm/vmsr_energy: Plug memory leak on failure to connect socket
Posted by Michael Tokarev 2 months, 1 week ago
On 23.07.2025 16:32, Markus Armbruster wrote:
> vmsr_open_socket() leaks the Error set by
> qio_channel_socket_connect_sync().  Plug the leak by not creating the
> Error.
> 
> Fixes: 0418f90809ae (Add support for RAPL MSRs in KVM/Qemu)

I'm picking this up for qemu-stable (10.0 & 10.1).
Please let me know if I shouldn't.

Thanks,

/mjt
Re: [PATCH 1/2] i386/kvm/vmsr_energy: Plug memory leak on failure to connect socket
Posted by Zhao Liu 2 months, 2 weeks ago
On Wed, Jul 23, 2025 at 03:32:56PM +0200, Markus Armbruster wrote:
> Date: Wed, 23 Jul 2025 15:32:56 +0200
> From: Markus Armbruster <armbru@redhat.com>
> Subject: [PATCH 1/2] i386/kvm/vmsr_energy: Plug memory leak on failure to
>  connect socket
> 
> vmsr_open_socket() leaks the Error set by
> qio_channel_socket_connect_sync().  Plug the leak by not creating the
> Error.
> 
> Fixes: 0418f90809ae (Add support for RAPL MSRs in KVM/Qemu)
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  target/i386/kvm/vmsr_energy.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>