All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-trivial] [PATCH] virtio-9p-proxy: Fix sockfd leak and modify the check logic
@ 2014-10-29 10:52 ` arei.gonglei
  0 siblings, 0 replies; 6+ messages in thread
From: arei.gonglei @ 2014-10-29 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Gonglei, weidong.huang, aneesh.kumar, mst

From: Gonglei <arei.gonglei@huawei.com>

If connect() return false, the sockfd will leak,
meanwhile proxy_init() can't check the return value
of connect_namedsocket(), maybe cause unpredictable
results.

Let's move the sock_id check logic out, which can
check both if and else statements.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/9pfs/virtio-9p-proxy.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
index b57966d..1c3aa5f 100644
--- a/hw/9pfs/virtio-9p-proxy.c
+++ b/hw/9pfs/virtio-9p-proxy.c
@@ -1112,6 +1112,7 @@ static int connect_namedsocket(const char *path)
     size = strlen(helper.sun_path) + sizeof(helper.sun_family);
     if (connect(sockfd, (struct sockaddr *)&helper, size) < 0) {
         fprintf(stderr, "socket error\n");
+        close(sockfd);
         return -1;
     }
 
@@ -1152,11 +1153,12 @@ static int proxy_init(FsContext *ctx)
         sock_id = connect_namedsocket(ctx->fs_root);
     } else {
         sock_id = atoi(ctx->fs_root);
-        if (sock_id < 0) {
-            fprintf(stderr, "socket descriptor not initialized\n");
-            g_free(proxy);
-            return -1;
-        }
+    }
+
+    if (sock_id < 0) {
+        fprintf(stderr, "socket descriptor not initialized\n");
+        g_free(proxy);
+        return -1;
     }
     g_free(ctx->fs_root);
     ctx->fs_root = NULL;
-- 
1.7.12.4




^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-10-30 10:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-29 10:52 [Qemu-trivial] [PATCH] virtio-9p-proxy: Fix sockfd leak and modify the check logic arei.gonglei
2014-10-29 10:52 ` [Qemu-devel] " arei.gonglei
2014-10-30  8:03 ` [Qemu-trivial] " Michael Tokarev
2014-10-30  8:03   ` [Qemu-devel] " Michael Tokarev
2014-10-30 10:51   ` Gonglei
2014-10-30 10:51     ` [Qemu-devel] " Gonglei

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.