diff mbox

gdbstub: Fix fd leak in gdbserver_open() error path

Message ID 1324769844-5991-1-git-send-email-peter.maydell@linaro.org
State Accepted
Commit bb16172c52ac18742f3df156912c169904e92147
Headers show

Commit Message

Peter Maydell Dec. 24, 2011, 11:37 p.m. UTC
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(-)

Comments

Stefan Hajnoczi Jan. 3, 2012, 10:51 a.m. UTC | #1
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
diff mbox

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;