Skip to contentSkip to conversation

vhost-user: fix memory leak

PATCH In review linzhecheng 4 participants 4 messages Feb 13, 2018 Networking

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vhost-user: fix memory leak

g_free() was moved from vhost_net_cleanup in commit e6bcb1b, so we should free net after vhost_net_cleanup

net/vhost-user.c +1 -0
index cb45512506..d024573e45 100644
@@ -109,6 +109,7 @@ static int vhost_user_start(int queues, NetClientState *ncs[], CharBackend *be)
 err:
     if (net) {
         vhost_net_cleanup(net);
+        g_free(net);
     }
     vhost_user_stop(i, ncs);
     return -1;
Signature · 1 line
2.12.2.windows.2
#1 lore raw
Quoted 4 lines · linzhecheng

g_free() was moved from vhost_net_cleanup in commit e6bcb1b, so we should free net after vhost_net_cleanup

Looks like this needs a Fixes: tag and CC stable - is that right?

Quoted 15 lines
net/vhost-user.c +1 -0
index cb45512506..d024573e45 100644
@@ -109,6 +109,7 @@ static int vhost_user_start(int queues, NetClientState *ncs[], CharBackend *be)
 err:
     if (net) {
         vhost_net_cleanup(net);
+        g_free(net);
     }
     vhost_user_stop(i, ncs);
     return -1;
Signature · 1 line
2.12.2.windows.2
Reviewed-by on v2 1/1
#2 lore raw
In reply to linzhecheng
Quoted 4 lines · linzhecheng

g_free() was moved from vhost_net_cleanup in commit e6bcb1b, so we should free net after vhost_net_cleanup

This can be reproduced and catched by ASAN too:

==11833==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 784 byte(s) in 1 object(s) allocated from:

    #0 0x7fa1aed89a38 in __interceptor_calloc (/lib64/libasan.so.4+0xdea38)
    #1 0x7fa1adadff75 in g_malloc0 ../glib/gmem.c:124
    #2 0x56082a195515 in vhost_net_init
/home/elmarco/src/qemu/hw/net/vhost_net.c:147
    #3 0x61500000bbff  (<unknown module>)

good catch,

Quoted 18 lines
net/vhost-user.c +1 -1
index cb45512506..d024573e45 100644
@@ -109,6 +109,7 @@ static int vhost_user_start(int queues, NetClientState *ncs[], CharBackend *be)
 err:
     if (net) {
         vhost_net_cleanup(net);
+        g_free(net);
     }
     vhost_user_stop(i, ncs);
     return -1;
--

2.12.2.windows.2

Signature · 1 line
Marc-André Lureau
Reviewed-by on v2 1/1
#3 lore raw
In reply to linzhecheng
Quoted 4 lines · linzhecheng

g_free() was moved from vhost_net_cleanup in commit e6bcb1b, so we should free net after vhost_net_cleanup

Quoted 14 lines
net/vhost-user.c +1 -0
index cb45512506..d024573e45 100644
@@ -109,6 +109,7 @@ static int vhost_user_start(int queues, NetClientState *ncs[], CharBackend *be)
 err:
     if (net) {
         vhost_net_cleanup(net);
+        g_free(net);
     }
     vhost_user_stop(i, ncs);
     return -1;