vhost: clean up per-socket mutex
authorDaniel Verkamp <daniel.verkamp@intel.com>
Mon, 12 Jun 2017 21:29:04 +0000 (14:29 -0700)
committerYuanhan Liu <yliu@fridaylinux.org>
Sat, 1 Jul 2017 23:16:31 +0000 (01:16 +0200)
vsocket->conn_mutex was allocated with pthread_mutex_init() but never
freed with pthread_mutex_destroy().  This is a potential memory leak,
depending on how pthread_mutex_t is implemented.

Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
lib/librte_vhost/socket.c

index c7f99b0..9720773 100644 (file)
@@ -636,6 +636,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
                vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);
                if (vsocket->reconnect && reconn_tid == 0) {
                        if (vhost_user_reconnect_init() < 0) {
+                               pthread_mutex_destroy(&vsocket->conn_mutex);
                                free(vsocket->path);
                                free(vsocket);
                                goto out;
@@ -646,6 +647,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
        }
        ret = create_unix_socket(vsocket);
        if (ret < 0) {
+               pthread_mutex_destroy(&vsocket->conn_mutex);
                free(vsocket->path);
                free(vsocket);
                goto out;
@@ -724,6 +726,7 @@ rte_vhost_driver_unregister(const char *path)
                        }
                        pthread_mutex_unlock(&vsocket->conn_mutex);
 
+                       pthread_mutex_destroy(&vsocket->conn_mutex);
                        free(vsocket->path);
                        free(vsocket);