gdbstub: Prevent fd leakage
authorPhilippe Mathieu-Daudé <f4bug@amsat.org>
Thu, 24 May 2018 22:34:58 +0000 (19:34 -0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 1 Jun 2018 13:14:31 +0000 (15:14 +0200)
Since 2f652224f7, we now check if socket_set_nodelay() errored,
but forgot to close the socket before reporting an error.

Fixes: Coverity CID 1391290 (RESOURCE_LEAK)
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180524223458.5651-1-f4bug@amsat.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
gdbstub.c

index 6081e719c531dc18fd8d15adc9fb69e23d59d7cf..d6ab95006c46d71aa800868a11919875da2a3bd4 100644 (file)
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1842,6 +1842,7 @@ static bool gdb_accept(void)
     /* set short latency */
     if (socket_set_nodelay(fd)) {
         perror("setsockopt");
+        close(fd);
         return false;
     }