net/socket.c: Fix fd leak in net_socket_listen_init() error paths
authorPeter Maydell <peter.maydell@linaro.org>
Sat, 24 Dec 2011 23:47:11 +0000 (23:47 +0000)
committerStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Fri, 6 Jan 2012 15:07:14 +0000 (15:07 +0000)
Fix a leak of a file descriptor due to missing closesocket() calls
in error paths in net_socket_listen_init().

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
net/socket.c

index aaf9be48e28bc7c5ae7180fc07823dd4d2409784..c9d70d388e9d23454f6f61d555916a03d0f0dac5 100644 (file)
@@ -427,12 +427,14 @@ static int net_socket_listen_init(VLANState *vlan,
     if (ret < 0) {
         perror("bind");
         g_free(s);
+        closesocket(fd);
         return -1;
     }
     ret = listen(fd, 0);
     if (ret < 0) {
         perror("listen");
         g_free(s);
+        closesocket(fd);
         return -1;
     }
     s->vlan = vlan;