net/virtio-user: check file descriptor before closing
authorStephen Hemminger <stephen@networkplumber.org>
Mon, 6 Jan 2020 19:18:37 +0000 (11:18 -0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 17 Jan 2020 18:46:02 +0000 (19:46 +0100)
Valgrind complains that virtio_user is calling close(-1).
Fix this by adding check in virtio that is similar to existing code.

Fixes: 37a7eb2ae816 ("net/virtio-user: add device emulation layer")
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>
drivers/net/virtio/virtio_user/virtio_user_dev.c

index ea016e8..ffbaa75 100644 (file)
@@ -537,7 +537,8 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev)
                close(dev->kickfds[i]);
        }
 
-       close(dev->vhostfd);
+       if (dev->vhostfd >= 0)
+               close(dev->vhostfd);
 
        if (dev->is_server && dev->listenfd >= 0) {
                close(dev->listenfd);