[Qemu-devel] [PATCH] io: fix mem leak in websock error path

Daniel P. Berrange posted 1 patch 6 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20171011153843.9876-1-berrange@redhat.com
Test checkpatch passed
Test docker passed
Test s390x passed
There is a newer version of this series
io/channel-websock.c | 1 +
1 file changed, 1 insertion(+)
[Qemu-devel] [PATCH] io: fix mem leak in websock error path
Posted by Daniel P. Berrange 6 years, 6 months ago
Coverity pointed out the 'date' is not free()d in the error
path

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 io/channel-websock.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/io/channel-websock.c b/io/channel-websock.c
index aa35ef3274..a1c10ab719 100644
--- a/io/channel-websock.c
+++ b/io/channel-websock.c
@@ -355,6 +355,7 @@ static void qio_channel_websock_handshake_send_res_ok(QIOChannelWebsock *ioc,
                             QIO_CHANNEL_WEBSOCK_GUID_LEN,
                             &accept,
                             errp) < 0) {
+        g_free(date);
         qio_channel_websock_handshake_send_res_err(
             ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_SERVER_ERR);
         return;
-- 
2.13.5


Re: [Qemu-devel] [PATCH] io: fix mem leak in websock error path
Posted by Eric Blake 6 years, 6 months ago
On 10/11/2017 10:38 AM, Daniel P. Berrange wrote:
> Coverity pointed out the 'date' is not free()d in the error
> path
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  io/channel-websock.c | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/io/channel-websock.c b/io/channel-websock.c
> index aa35ef3274..a1c10ab719 100644
> --- a/io/channel-websock.c
> +++ b/io/channel-websock.c
> @@ -355,6 +355,7 @@ static void qio_channel_websock_handshake_send_res_ok(QIOChannelWebsock *ioc,
>                              QIO_CHANNEL_WEBSOCK_GUID_LEN,
>                              &accept,
>                              errp) < 0) {
> +        g_free(date);
>          qio_channel_websock_handshake_send_res_err(
>              ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_SERVER_ERR);
>          return;
> 

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

Re: [Qemu-devel] [PATCH] io: fix mem leak in websock error path
Posted by Philippe Mathieu-Daudé 6 years, 6 months ago
Hi Daniel,

On 10/11/2017 12:38 PM, Daniel P. Berrange wrote:
> Coverity pointed out the 'date' is not free()d in the error
> path
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  io/channel-websock.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/io/channel-websock.c b/io/channel-websock.c
> index aa35ef3274..a1c10ab719 100644
> --- a/io/channel-websock.c
> +++ b/io/channel-websock.c
> @@ -355,6 +355,7 @@ static void qio_channel_websock_handshake_send_res_ok(QIOChannelWebsock *ioc,
>                              QIO_CHANNEL_WEBSOCK_GUID_LEN,
>                              &accept,
>                              errp) < 0) {
> +        g_free(date);

It looks cleaner to only call qio_channel_websock_date_str() before to
use date, which is _after_ qcrypto_hash_base64() might fails.

>          qio_channel_websock_handshake_send_res_err(
>              ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_SERVER_ERR);
>          return;
    }

+   date = qio_channel_websock_date_str();
    qio_channel_websock_handshake_send_res(
        ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_OK, date, accept);

    g_free(date);
    g_free(accept);
}