Patchwork [7/9] net/socket.c: Fix fd leak in net_socket_listen_init() error paths

login
register
mail settings
Submitter Stefan Hajnoczi
Date Jan. 6, 2012, 3:51 p.m.
Message ID <1325865088-23897-8-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/134671/
State New
Headers show

Comments

Stefan Hajnoczi - Jan. 6, 2012, 3:51 p.m.
From: Peter Maydell <peter.maydell@linaro.org>

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 |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Patch

diff --git a/net/socket.c b/net/socket.c
index aaf9be4..c9d70d3 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -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;