Skip to contentSkip to conversation

gdbstub: Prevent fd leakage

PATCH In review Philippe Mathieu-Daudé 3 participants 3 messages May 24, 2018 – May 25, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gdbstub: Prevent fd leakage

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)
---
 gdbstub.c | 1 +
 1 file changed, 1 insertion(+)
gdbstub.c +1 -0
index e4ece2f5bc..9c860cd81c 100644
@@ -1836,6 +1836,7 @@ static bool gdb_accept(void)
     /* set short latency */
     if (socket_set_nodelay(fd)) {
         perror("setsockopt");
+        close(fd);
         return false;
     }
 
Signature · 1 line
2.17.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Philippe Mathieu-Daudé

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)
---
 gdbstub.c | 1 +
 1 file changed, 1 insertion(+)
gdbstub.c +0 -0
index e4ece2f5bc..9c860cd81c 100644

gdbstub.c static bool gdb_accept(void) · line 1841

Quoted 6 lines
gdbstub.c +1 -0
@@ -1836,6 +1836,7 @@ static bool gdb_accept(void)
     /* set short latency */
     if (socket_set_nodelay(fd)) {
         perror("setsockopt");
+        close(fd);
         return false;
     }
Reviewed-by on v1 1/1
#2 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé

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)
---
 gdbstub.c | 1 +
 1 file changed, 1 insertion(+)
gdbstub.c +0 -0
index e4ece2f5bc..9c860cd81c 100644

gdbstub.c static bool gdb_accept(void) · line 1841

Quoted 6 lines
gdbstub.c +1 -0
@@ -1836,6 +1836,7 @@ static bool gdb_accept(void)
     /* set short latency */
     if (socket_set_nodelay(fd)) {
         perror("setsockopt");
+        close(fd);
         return false;
     }

thanks
-- PMM