Skip to contentSkip to conversation

io: fix mem leak in websock error path

PATCH Superseded Daniel P. Berrange 3 participants 3 messages Oct 11, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io: fix mem leak in websock error path

Coverity pointed out the 'date' is not free()d in the error path

---
 io/channel-websock.c | 1 +
 1 file changed, 1 insertion(+)
io/channel-websock.c +1 -0
index aa35ef3274..a1c10ab719 100644
@@ -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;
Signature · 1 line
2.13.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Daniel P. Berrange

Coverity pointed out the 'date' is not free()d in the error path

---
 io/channel-websock.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 14 lines
io/channel-websock.c +1 -0
index aa35ef3274..a1c10ab719 100644
@@ -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;
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#2 lore raw
In reply to Daniel P. Berrange

Hi Daniel,

Quoted 13 lines · Daniel P. Berrange

Coverity pointed out the 'date' is not free()d in the error path

---
 io/channel-websock.c | 1 +
 1 file changed, 1 insertion(+)
io/channel-websock.c +0 -0
index aa35ef3274..a1c10ab719 100644

io/channel-websock.c static void qio_channel_websock_handshake_send_res_ok(QIOChannelWebsock *ioc, · line 358

Quoted 4 lines
io/channel-websock.c +1 -0
@@ -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.

io/channel-websock.c static void qio_channel_websock_handshake_send_res_ok(QIOChannelWebsock *ioc, · line 361

Quoted 3 lines
io/channel-websock.c +0 -0
         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);
}