diff mbox series

contrib/plugins: Close file descriptor on connect failure

Message ID 20231016093143.222551-1-liucong2@kylinos.cn
State New
Headers show
Series contrib/plugins: Close file descriptor on connect failure | expand

Commit Message

Cong Liu Oct. 16, 2023, 9:31 a.m. UTC
This patch closes the file descriptor fd on connect failure to avoid
resource leak.

Signed-off-by: Cong Liu <liucong2@kylinos.cn>
---
 contrib/plugins/lockstep.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Alex Bennée Oct. 23, 2023, 1:44 p.m. UTC | #1
Cong Liu <liucong2@kylinos.cn> writes:

> This patch closes the file descriptor fd on connect failure to avoid
> resource leak.
>
> Signed-off-by: Cong Liu <liucong2@kylinos.cn>
> ---
>  contrib/plugins/lockstep.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/contrib/plugins/lockstep.c b/contrib/plugins/lockstep.c
> index f0cb8792c6fa..3c0f2b485181 100644
> --- a/contrib/plugins/lockstep.c
> +++ b/contrib/plugins/lockstep.c
> @@ -303,6 +303,7 @@ static bool connect_socket(const char *path)
>      sockaddr.sun_family = AF_UNIX;
>      if (g_strlcpy(sockaddr.sun_path, path, pathlen) >= pathlen) {
>          perror("bad path");
> +        close(fd);
>          return false;
>      }

Queued to plugins/next, thanks.
diff mbox series

Patch

diff --git a/contrib/plugins/lockstep.c b/contrib/plugins/lockstep.c
index f0cb8792c6fa..3c0f2b485181 100644
--- a/contrib/plugins/lockstep.c
+++ b/contrib/plugins/lockstep.c
@@ -303,6 +303,7 @@  static bool connect_socket(const char *path)
     sockaddr.sun_family = AF_UNIX;
     if (g_strlcpy(sockaddr.sun_path, path, pathlen) >= pathlen) {
         perror("bad path");
+        close(fd);
         return false;
     }