Skip to contentSkip to conversation

plugins: Fix some resource leaks

PATCH Applied Alex Chen 2 participants 4 messages Nov 9, 2020 – Nov 10, 2020

lore
Share & tools
lore

Alex Chen

author
#0 lore raw

v3 cover plugins: Fix some resource leaks

There are 3 resource leaks in contrib/plugins/lockstep.c, fix it.

v2->v3:
- change the "From" line to "Alex Chen"

v1->v2:
- add the cover letter
- modify the subject of the patch[2/2]

Alex Chen (2):
plugins: Fix resource leak in connect_socket()
plugins: Fix two resource leaks in setup_socket()

 contrib/plugins/lockstep.c | 3 +++
 1 file changed, 3 insertions(+)
Signature · 1 line
2.19.1
author
#1 lore raw

PATCH v3 1/2 plugins: Fix resource leak in connect_socket()

Close the fd when the connect() fails.

---
 contrib/plugins/lockstep.c | 1 +
 1 file changed, 1 insertion(+)
contrib/plugins/lockstep.c +1 -0
index a696673dff..319bd44b83 100644
@@ -292,6 +292,7 @@ static bool connect_socket(const char *path)
 
     if (connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
         perror("failed to connect");
+        close(fd);
         return false;
     }
 
Signature · 1 line
2.19.1
author
#2 lore raw

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

In reply to Alex Chen

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
Applied
#3 lore raw
In reply to Alex Chen
Quoted 1 line · Alex Chen

There are 3 resource leaks in contrib/plugins/lockstep.c, fix it.

Queued to for-5.2/various-fixes, thanks.

Quoted 14 lines

v2->v3:
- change the "From" line to "Alex Chen"

v1->v2:
- add the cover letter
- modify the subject of the patch[2/2]

Alex Chen (2):
plugins: Fix resource leak in connect_socket()
plugins: Fix two resource leaks in setup_socket()

 contrib/plugins/lockstep.c | 3 +++
 1 file changed, 3 insertions(+)
Signature · 1 line
Alex Bennée