Skip to contentSkip to conversation

A fix and cleanup around qio_channel_socket_connect_sync()

PATCH Applied Markus Armbruster 3 participants 9 messages Jul 23, 2025 – Sep 3, 2025 KVM

lore
Share & tools
lore
#0 lore raw

cover A fix and cleanup around qio_channel_socket_connect_sync()

Markus Armbruster (2):
i386/kvm/vmsr_energy: Plug memory leak on failure to connect socket vfio scsi ui: Error-check qio_channel_socket_connect_sync() the same
way

 hw/vfio-user/proxy.c          | 2 +-
 scsi/pr-manager-helper.c      | 9 ++-------
 target/i386/kvm/vmsr_energy.c | 6 +-----
 ui/input-barrier.c            | 5 +----
 4 files changed, 5 insertions(+), 17 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

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)
---
 target/i386/kvm/vmsr_energy.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
target/i386/kvm/vmsr_energy.c +1 -5
index 58ce3df53a..890322ae37 100644
@@ -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));
Signature · 1 line
2.49.0
Reviewed-by on v1 1/2
#2 lore raw

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

Quoted 9 lines · Markus Armbruster

Date: Wed, 23 Jul 2025 15:32:56 +0200
From: Markus Armbruster <[email protected]>
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.

Quoted 5 lines
Fixes 0418f90809ae (Add support for RAPL MSRs in KVM/Qemu)
---
 target/i386/kvm/vmsr_energy.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
#3 lore raw

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

In reply to Markus Armbruster
Quoted 5 lines · Markus Armbruster

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

#4 lore raw

PATCH 2/2 vfio scsi ui: Error-check qio_channel_socket_connect_sync() the same way

In reply to Markus Armbruster

qio_channel_socket_connect_sync() returns 0 on success, and -1 on failure, with errp set. Some callers check the return value, and some check whether errp was set.

For consistency, always check the return value, and always check it's negative.

---
 hw/vfio-user/proxy.c     | 2 +-
 scsi/pr-manager-helper.c | 9 ++-------
 ui/input-barrier.c       | 5 +----
 3 files changed, 4 insertions(+), 12 deletions(-)
hw/vfio-user/proxy.c +1 -1
index 2275d3fe39..2c03d49f97 100644
@@ -885,7 +885,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *addr, Error **errp)
 
     sioc = qio_channel_socket_new();
     ioc = QIO_CHANNEL(sioc);
-    if (qio_channel_socket_connect_sync(sioc, addr, errp)) {
+    if (qio_channel_socket_connect_sync(sioc, addr, errp) < 0) {
         object_unref(OBJECT(ioc));
         return NULL;
     }
scsi/pr-manager-helper.c +2 -7
index 6b86f01b01..aea751fb04 100644
@@ -105,20 +105,15 @@ static int pr_manager_helper_initialize(PRManagerHelper *pr_mgr,
         .u.q_unix.path = path
     };
     QIOChannelSocket *sioc = qio_channel_socket_new();
-    Error *local_err = NULL;
-
     uint32_t flags;
     int r;
 
     assert(!pr_mgr->ioc);
     qio_channel_set_name(QIO_CHANNEL(sioc), "pr-manager-helper");
-    qio_channel_socket_connect_sync(sioc,
-                                    &saddr,
-                                    &local_err);
+    r = qio_channel_socket_connect_sync(sioc, &saddr, errp);
     g_free(path);
-    if (local_err) {
+    if (r < 0) {
         object_unref(OBJECT(sioc));
-        error_propagate(errp, local_err);
         return -ENOTCONN;
     }
 
ui/input-barrier.c +1 -4
index 9793258aac..0a2198ca50 100644
@@ -490,7 +490,6 @@ static gboolean input_barrier_event(QIOChannel *ioc G_GNUC_UNUSED,
 static void input_barrier_complete(UserCreatable *uc, Error **errp)
 {
     InputBarrier *ib = INPUT_BARRIER(uc);
-    Error *local_err = NULL;
 
     if (!ib->name) {
         error_setg(errp, QERR_MISSING_PARAMETER, "name");
@@ -506,9 +505,7 @@ static void input_barrier_complete(UserCreatable *uc, Error **errp)
     ib->sioc = qio_channel_socket_new();
     qio_channel_set_name(QIO_CHANNEL(ib->sioc), "barrier-client");
 
-    qio_channel_socket_connect_sync(ib->sioc, &ib->saddr, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (qio_channel_socket_connect_sync(ib->sioc, &ib->saddr, errp) < 0) {
         return;
     }
 
Signature · 1 line
2.49.0
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] vfio scsi ui: Error-check qio_channel_socket_connect_sync() the same way

Quoted 12 lines · Markus Armbruster

Date: Wed, 23 Jul 2025 15:32:57 +0200
From: Markus Armbruster <[email protected]>
Subject: [PATCH 2/2] vfio scsi ui: Error-check
qio_channel_socket_connect_sync() the same way

qio_channel_socket_connect_sync() returns 0 on success, and -1 on failure, with errp set. Some callers check the return value, and some check whether errp was set.

For consistency, always check the return value, and always check it's negative.

Quoted 6 lines
---
 hw/vfio-user/proxy.c     | 2 +-
 scsi/pr-manager-helper.c | 9 ++-------
 ui/input-barrier.c       | 5 +----
 3 files changed, 4 insertions(+), 12 deletions(-)
#6 lore raw

Re: [PATCH 2/2] vfio scsi ui: Error-check qio_channel_socket_connect_sync() the same way

In reply to Markus Armbruster
Quoted 6 lines · Markus Armbruster

qio_channel_socket_connect_sync() returns 0 on success, and -1 on failure, with errp set. Some callers check the return value, and some check whether errp was set.

For consistency, always check the return value, and always check it's negative.

Ditto for this one - applying this for qemu-stable (10.0 & 10.1). It doesn't hurt, and the code in longer-supported branches will be less different from the master branch, making future changes, if any, easier to pick up (there were multiple fixes in this area recently).

Please let me know if I shouldn't :)

Thanks,

/mjt