Skip to contentSkip to conversation

plugins: Fix two resource leaks in connect_socket()

PATCH In review AlexChen 3 participants 6 messages Oct 28, 2020 – Nov 17, 2020

lore
Share & tools
lore

AlexChen

author
#0 lore raw

PATCH 2/2 plugins: Fix two resource leaks in connect_socket()

Either accept() fails or exits normally, we need to close the fd.

---
 contrib/plugins/lockstep.c | 2 ++
 1 file changed, 2 insertions(+)
contrib/plugins/lockstep.c +2 -0
index 319bd44b83..5aad50869d 100644
@@ -268,11 +268,13 @@ static bool setup_socket(const char *path)
     socket_fd = accept(fd, NULL, NULL);
     if (socket_fd < 0 && errno != EINTR) {
         perror("accept socket");
+        close(fd);
         return false;
     }
 
     qemu_plugin_outs("setup_socket::ready\n");
 
+    close(fd);
     return true;
 }
 
Signature · 1 line
2.19.1
author
#1 lore raw

Kindly ping.

Quoted 26 lines · AlexChen

Either accept() fails or exits normally, we need to close the fd.

---
 contrib/plugins/lockstep.c | 2 ++
 1 file changed, 2 insertions(+)
contrib/plugins/lockstep.c +2 -0
index 319bd44b83..5aad50869d 100644
@@ -268,11 +268,13 @@ static bool setup_socket(const char *path)
     socket_fd = accept(fd, NULL, NULL);
     if (socket_fd < 0 && errno != EINTR) {
         perror("accept socket");
+        close(fd);
         return false;
     }
 
     qemu_plugin_outs("setup_socket::ready\n");
 
+    close(fd);
     return true;
 }
 
#2 lore raw
In reply to AlexChen
Quoted 13 lines · AlexChen

Either accept() fails or exits normally, we need to close the fd.

---
 contrib/plugins/lockstep.c | 2 ++
 1 file changed, 2 insertions(+)
contrib/plugins/lockstep.c +0 -0
index 319bd44b83..5aad50869d 100644

contrib/plugins/lockstep.c static bool setup_socket(const char *path) · line 268

Quoted 1 line
contrib/plugins/lockstep.c +0 -0
@@ -268,11 +268,13 @@ static bool setup_socket(const char *path)
     socket_fd = accept(fd, NULL, NULL);

I think you could also simply close(fd) here instead, then you don't have to do it twice below.

Thomas

Quoted 12 lines
contrib/plugins/lockstep.c +2 -0
     if (socket_fd < 0 && errno != EINTR) {
         perror("accept socket");
+        close(fd);
         return false;
     }
 
     qemu_plugin_outs("setup_socket::ready\n");
 
+    close(fd);
     return true;
 }
 
author
#3 lore raw
Quoted 9 lines · Thomas Huth
Quoted 8 lines · AlexChen

Either accept() fails or exits normally, we need to close the fd.

---
 contrib/plugins/lockstep.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 10 lines

contrib/plugins/lockstep.c static bool setup_socket(const char *path) · line 268

Quoted 6 lines
contrib/plugins/lockstep.c +0 -0
index 319bd44b83..5aad50869d 100644
@@ -268,11 +268,13 @@ static bool setup_socket(const char *path)
     socket_fd = accept(fd, NULL, NULL);

I think you could also simply close(fd) here instead, then you don't have to do it twice below.

Hi Thomas and Alex,
Thanks for your suggestion. It's a simple and effective solution. Considering that the patch v3 has been queued by Alex Bennée, May I modify this patch and then send patch v4?

Thanks,
Alex

Quoted 16 lines

contrib/plugins/lockstep.c static bool setup_socket(const char *path) · line 280

Quoted 13 lines
contrib/plugins/lockstep.c +2 -0
     if (socket_fd < 0 && errno != EINTR) {
         perror("accept socket");
+        close(fd);
         return false;
     }
 
     qemu_plugin_outs("setup_socket::ready\n");
 
+    close(fd);
     return true;
 }
 

.

#4 lore raw
Quoted 21 lines · Alex Chen
Quoted 9 lines · Thomas Huth
Quoted 8 lines · AlexChen

Either accept() fails or exits normally, we need to close the fd.

---
 contrib/plugins/lockstep.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 10 lines

contrib/plugins/lockstep.c static bool setup_socket(const char *path) · line 268

Quoted 6 lines
contrib/plugins/lockstep.c +0 -0
index 319bd44b83..5aad50869d 100644
@@ -268,11 +268,13 @@ static bool setup_socket(const char *path)
     socket_fd = accept(fd, NULL, NULL);

I think you could also simply close(fd) here instead, then you don't have to do it twice below.

Quoted 4 lines

Hi Thomas and Alex,
Thanks for your suggestion. It's a simple and effective solution. Considering that the patch v3 has been queued by Alex Bennée, May I modify this patch and then send patch v4?

The fix has already been merged so a fresh patch would make more sense.

Signature · 1 line
Alex Bennée
#5 lore raw
Quoted 24 lines · Alex Bennée
Quoted 21 lines · Alex Chen
Quoted 19 lines · Thomas Huth
Quoted 13 lines · AlexChen

Either accept() fails or exits normally, we need to close the fd.

---
 contrib/plugins/lockstep.c | 2 ++
 1 file changed, 2 insertions(+)
contrib/plugins/lockstep.c +0 -0
index 319bd44b83..5aad50869d 100644

contrib/plugins/lockstep.c static bool setup_socket(const char *path) · line 268

Quoted 1 line
contrib/plugins/lockstep.c +0 -0
@@ -268,11 +268,13 @@ static bool setup_socket(const char *path)
     socket_fd = accept(fd, NULL, NULL);

I think you could also simply close(fd) here instead, then you don't have to do it twice below.

Quoted 6 lines
Quoted 4 lines

Hi Thomas and Alex,
Thanks for your suggestion. It's a simple and effective solution. Considering that the patch v3 has been queued by Alex Bennée, May I modify this patch and then send patch v4?

The fix has already been merged so a fresh patch would make more sense.

Well, then never mind. It's not worth the code churn to just get rid of one line of code, I think.

Thomas