Patchwork gdbstub: Fix fd leak in gdbserver_open() error path

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

Comments

Peter Maydell - Dec. 24, 2011, 11:37 p.m.
Fix a leak of a file descriptor in error exit paths in
gdbserver_open().

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Of no great consequence, but it was in the pile of coverity complaints
and it's a trivial fix.

 gdbstub.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:37:24PM +0000, Peter Maydell wrote:
> Fix a leak of a file descriptor in error exit paths in
> gdbserver_open().
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Of no great consequence, but it was in the pile of coverity complaints
> and it's a trivial fix.
> 
>  gdbstub.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/gdbstub.c b/gdbstub.c
index a5806ef..7d470b6 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2762,11 +2762,13 @@  static int gdbserver_open(int port)
     ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
     if (ret < 0) {
         perror("bind");
+        close(fd);
         return -1;
     }
     ret = listen(fd, 0);
     if (ret < 0) {
         perror("listen");
+        close(fd);
         return -1;
     }
     return fd;