virtfs-proxy-helper: Fix possible socket leak.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
Gonglei 2014-11-13 20:17:06 +08:00 committed by Michael Tokarev
parent 46ede58bb4
commit 88ea8ed74c

View File

@ -749,24 +749,29 @@ static int proxy_socket(const char *path, uid_t uid, gid_t gid)
if (bind(sock, (struct sockaddr *)&proxy, if (bind(sock, (struct sockaddr *)&proxy,
sizeof(struct sockaddr_un)) < 0) { sizeof(struct sockaddr_un)) < 0) {
do_perror("bind"); do_perror("bind");
return -1; goto error;
} }
if (chown(proxy.sun_path, uid, gid) < 0) { if (chown(proxy.sun_path, uid, gid) < 0) {
do_perror("chown"); do_perror("chown");
return -1; goto error;
} }
if (listen(sock, 1) < 0) { if (listen(sock, 1) < 0) {
do_perror("listen"); do_perror("listen");
return -1; goto error;
} }
size = sizeof(qemu); size = sizeof(qemu);
client = accept(sock, (struct sockaddr *)&qemu, &size); client = accept(sock, (struct sockaddr *)&qemu, &size);
if (client < 0) { if (client < 0) {
do_perror("accept"); do_perror("accept");
return -1; goto error;
} }
close(sock);
return client; return client;
error:
close(sock);
return -1;
} }
static void usage(char *prog) static void usage(char *prog)