Skip to contentSkip to conversation

qemu-nbd: Fix a memleak in qemu_nbd_client_list()

PATCH In review Alex Chen 3 participants 3 messages Nov 30, 2020

lore
Share & tools
lore

Alex Chen

author
#0 lore raw

PATCH 1/1 qemu-nbd: Fix a memleak in qemu_nbd_client_list()

When the qio_channel_socket_connect_sync() fails
we should goto 'out' label to free the 'sioc' instead of return.

---
 qemu-nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-nbd.c +1 -1
index a7075c5419..47587a709e 100644
@@ -181,7 +181,7 @@ static int qemu_nbd_client_list(SocketAddress *saddr, QCryptoTLSCreds *tls,
     sioc = qio_channel_socket_new();
     if (qio_channel_socket_connect_sync(sioc, saddr, &err) < 0) {
         error_report_err(err);
-        return EXIT_FAILURE;
+        goto out;
     }
     rc = nbd_receive_export_list(QIO_CHANNEL(sioc), tls, hostname, &list,
                                  &err);
Signature · 1 line
2.19.1
#2 lore raw
In reply to Alex Chen
Quoted 8 lines · Alex Chen

When the qio_channel_socket_connect_sync() fails
we should goto 'out' label to free the 'sioc' instead of return.

---
 qemu-nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

A local leak, but the only caller of qemu_nbd_client_list() is main() which returns the value and thereby exits the program, so it is inconsequential in the bigger picture. I'll defer this to 6.0, and pick it up through my NBD tree once that opens.

Quoted 15 lines
qemu-nbd.c +1 -1
index a7075c5419..47587a709e 100644
@@ -181,7 +181,7 @@ static int qemu_nbd_client_list(SocketAddress *saddr, QCryptoTLSCreds *tls,
     sioc = qio_channel_socket_new();
     if (qio_channel_socket_connect_sync(sioc, saddr, &err) < 0) {
         error_report_err(err);
-        return EXIT_FAILURE;
+        goto out;
     }
     rc = nbd_receive_export_list(QIO_CHANNEL(sioc), tls, hostname, &list,
                                  &err);
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org