From 88ea8ed74cb6956f43199a098ca4963ae73bba57 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Thu, 13 Nov 2014 20:17:06 +0800 Subject: [PATCH] virtfs-proxy-helper: Fix possible socket leak. Signed-off-by: Gonglei Reviewed-by: Markus Armbruster Signed-off-by: Michael Tokarev --- fsdev/virtfs-proxy-helper.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c index cd291d32f2..c1da2d78e7 100644 --- a/fsdev/virtfs-proxy-helper.c +++ b/fsdev/virtfs-proxy-helper.c @@ -749,24 +749,29 @@ static int proxy_socket(const char *path, uid_t uid, gid_t gid) if (bind(sock, (struct sockaddr *)&proxy, sizeof(struct sockaddr_un)) < 0) { do_perror("bind"); - return -1; + goto error; } if (chown(proxy.sun_path, uid, gid) < 0) { do_perror("chown"); - return -1; + goto error; } if (listen(sock, 1) < 0) { do_perror("listen"); - return -1; + goto error; } size = sizeof(qemu); client = accept(sock, (struct sockaddr *)&qemu, &size); if (client < 0) { do_perror("accept"); - return -1; + goto error; } + close(sock); return client; + +error: + close(sock); + return -1; } static void usage(char *prog)