[PATCH] qemu-nbd: Fix a memleak in qemu_nbd_client_list()

Alex Chen posted 1 patch 3 years, 5 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20201130123651.17543-1-alex.chen@huawei.com
Maintainers: Eric Blake <eblake@redhat.com>
qemu-nbd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] qemu-nbd: Fix a memleak in qemu_nbd_client_list()
Posted by Alex Chen 3 years, 5 months ago
When the qio_channel_socket_connect_sync() fails
we should goto 'out' label to free the 'sioc' instead of return.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Alex Chen <alex.chen@huawei.com>
---
 qemu-nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qemu-nbd.c b/qemu-nbd.c
index a7075c5419..47587a709e 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -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);
-- 
2.19.1


Re: [PATCH] qemu-nbd: Fix a memleak in qemu_nbd_client_list()
Posted by Alberto Garcia 3 years, 5 months ago
On Mon 30 Nov 2020 01:36:51 PM CET, Alex Chen wrote:
> When the qio_channel_socket_connect_sync() fails
> we should goto 'out' label to free the 'sioc' instead of return.
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Alex Chen <alex.chen@huawei.com>

Reviewed-by: Alberto Garcia <berto@igalia.com>

Berto

Re: [PATCH] qemu-nbd: Fix a memleak in qemu_nbd_client_list()
Posted by Eric Blake 3 years, 5 months ago
On 11/30/20 6:36 AM, Alex Chen wrote:
> When the qio_channel_socket_connect_sync() fails
> we should goto 'out' label to free the 'sioc' instead of return.
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Alex Chen <alex.chen@huawei.com>
> ---
>  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.

> 
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index a7075c5419..47587a709e 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -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);
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org