[PATCH] contrib/plugins: Close file descriptor on connect failure

Cong Liu posted 1 patch 1 year, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20231016093143.222551-1-liucong2@kylinos.cn
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>
contrib/plugins/lockstep.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] contrib/plugins: Close file descriptor on connect failure
Posted by Cong Liu 1 year, 1 month ago
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;
     }
 
-- 
2.34.1
Re: [PATCH] contrib/plugins: Close file descriptor on connect failure
Posted by Alex Bennée 1 year, 1 month ago
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.

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
[PATCH v2] contrib/plugins: Close file descriptor on error return
Posted by Cong Liu 1 year, 1 month ago
This patch closes the file descriptor fd on error return to avoid
resource leak.

Fixes: ec7ee95db909 ("contrib/plugins: fix coverity warning in lockstep")
Signed-off-by: Cong Liu <liucong2@kylinos.cn>
---
 contrib/plugins/lockstep.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/contrib/plugins/lockstep.c b/contrib/plugins/lockstep.c
index f0cb8792c6fa..237543b43a76 100644
--- a/contrib/plugins/lockstep.c
+++ b/contrib/plugins/lockstep.c
@@ -257,6 +257,7 @@ static bool setup_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;
     }
 
@@ -303,6 +304,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;
     }
 
-- 
2.34.1
Re: [PATCH v2] contrib/plugins: Close file descriptor on error return
Posted by Alex Bennée 1 year, 1 month ago
Cong Liu <liucong2@kylinos.cn> writes:

> This patch closes the file descriptor fd on error return to avoid
> resource leak.
>
> Fixes: ec7ee95db909 ("contrib/plugins: fix coverity warning in lockstep")
> Signed-off-by: Cong Liu <liucong2@kylinos.cn>
> ---
>  contrib/plugins/lockstep.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/contrib/plugins/lockstep.c b/contrib/plugins/lockstep.c
> index f0cb8792c6fa..237543b43a76 100644
> --- a/contrib/plugins/lockstep.c
> +++ b/contrib/plugins/lockstep.c
> @@ -257,6 +257,7 @@ static bool setup_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;
>      }
>  
> @@ -303,6 +304,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;
>      }

Sorry queued this version to plugins/next, thanks.

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro