vhost: fix memory leak
authorYuanhan Liu <yuanhan.liu@linux.intel.com>
Tue, 28 Jun 2016 03:58:29 +0000 (11:58 +0800)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Mon, 4 Jul 2016 02:08:41 +0000 (04:08 +0200)
Fix potential memory leak raised by Coverity.

    >>>     Variable "vsocket" going out of scope leaks the storage it
    >>>     points to.

Coverity issue: 127483
Fixes: e623e0c6d8a5 ("vhost: add reconnect ability")

Reported-by: John McNamara <john.mcnamara@intel.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
lib/librte_vhost/vhost_user/vhost-net-user.c

index 94f1b92..90cc127 100644 (file)
@@ -617,8 +617,11 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
        if ((flags & RTE_VHOST_USER_CLIENT) != 0) {
                vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);
                if (vsocket->reconnect && reconn_tid == 0) {
-                       if (vhost_user_reconnect_init() < 0)
+                       if (vhost_user_reconnect_init() < 0) {
+                               free(vsocket->path);
+                               free(vsocket);
                                goto out;
+                       }
                }
                ret = vhost_user_create_client(vsocket);
        } else {