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

login
register
mail settings
Submitter Peter Maydell
Date Dec. 24, 2011, 11:47 p.m.
Message ID <1324770431-6074-1-git-send-email-peter.maydell@linaro.org>
Download mbox | patch
Permalink /patch/133167/
State New
Headers show

Comments

Peter Maydell - Dec. 24, 2011, 11:47 p.m.
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>
---
Coverity again...

 net/socket.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Stefan Hajnoczi - Jan. 3, 2012, 10:51 a.m.
On Sat, Dec 24, 2011 at 11:47:11PM +0000, Peter Maydell wrote:
> 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>
> ---
> Coverity again...
> 
>  net/socket.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)

Thanks, applied to the trivial patches -next tree:
https://github.com/stefanha/qemu/commits/trivial-patches-next

Stefan

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;