plugins: Fix two resource leaks in connect_socket()
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
@@ -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
Kindly ping.
Quoted 26 lines · AlexChen
Either
accept()fails or exits normally, we need to close the fd.Reported-by Euler Robot <[email protected]>Signed-off-by AlexChen <[email protected]>--- contrib/plugins/lockstep.c | 2 ++ 1 file changed, 2 insertions(+)contrib/plugins/lockstep.c +2
-0@@ -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; }
Quoted 13 lines · AlexChen
Either
accept()fails or exits normally, we need to close the fd.Reported-by Euler Robot <[email protected]>Signed-off-by AlexChen <[email protected]>--- contrib/plugins/lockstep.c | 2 ++ 1 file changed, 2 insertions(+)contrib/plugins/lockstep.c +0
-0
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
-0if (socket_fd <0 && errno !=EINTR ) {perror ("accept socket" ); +close (fd);return false; }qemu_plugin_outs ("setup_socket::ready\n" ); +close (fd);return true; }
Quoted 9 lines · Thomas Huth
Quoted 8 lines · AlexChen
Either
accept()fails or exits normally, we need to close the fd.Reported-by Euler Robot <[email protected]>Signed-off-by AlexChen <[email protected]>--- 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@@ -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
-0if (socket_fd <0 && errno !=EINTR ) {perror ("accept socket" ); +close (fd);return false; }qemu_plugin_outs ("setup_socket::ready\n" ); +close (fd);return true; }.
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.Reported-by Euler Robot <[email protected]>Signed-off-by AlexChen <[email protected]>--- 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@@ -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
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.Reported-by Euler Robot <[email protected]>Signed-off-by AlexChen <[email protected]>--- contrib/plugins/lockstep.c | 2 ++ 1 file changed, 2 insertions(+)contrib/plugins/lockstep.c +0
-0contrib/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