Patchwork [3/6] qemu-ga: Plug file descriptor leak on ga_open_pidfile() error path

login
register
mail settings
Submitter Markus Armbruster
Date Jan. 11, 2013, 10:24 a.m.
Message ID <1357899902-5316-4-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/211288/
State New
Headers show

Comments

Markus Armbruster - Jan. 11, 2013, 10:24 a.m.
Spotted by Coverity.  Also document why we keep it open on success.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 qga/main.c | 2 ++
 1 file changed, 2 insertions(+)
Michael Roth - Jan. 11, 2013, 5:42 p.m.
On Fri, Jan 11, 2013 at 11:24:59AM +0100, Markus Armbruster wrote:
> Spotted by Coverity.  Also document why we keep it open on success.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>

> ---
>  qga/main.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/qga/main.c b/qga/main.c
> index 1a22d8d..db47427 100644
> --- a/qga/main.c
> +++ b/qga/main.c
> @@ -286,10 +286,12 @@ static bool ga_open_pidfile(const char *pidfile)
>          goto fail;
>      }
> 
> +    /* keep pidfile open & locked forever */
>      return true;
> 
>  fail:
>      unlink(pidfile);
> +    close(pidfd);
>      return false;
>  }
>  #else /* _WIN32 */
> -- 
> 1.7.11.7
>

Patch

diff --git a/qga/main.c b/qga/main.c
index 1a22d8d..db47427 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -286,10 +286,12 @@  static bool ga_open_pidfile(const char *pidfile)
         goto fail;
     }
 
+    /* keep pidfile open & locked forever */
     return true;
 
 fail:
     unlink(pidfile);
+    close(pidfd);
     return false;
 }
 #else /* _WIN32 */