diff mbox

[for-3.0] qga: fix file descriptor leak

Message ID 20180715162156.12394-1-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Paolo Bonzini July 15, 2018, 4:21 p.m. UTC
The file descriptor for /sys/power/state was never closed.  Reported
by Coverity.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qga/commands-posix.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Philippe Mathieu-Daudé July 15, 2018, 10:22 p.m. UTC | #1
On 07/15/2018 01:21 PM, Paolo Bonzini wrote:
> The file descriptor for /sys/power/state was never closed.  Reported
> by Coverity.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  qga/commands-posix.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 233f78a406..4160aceaed 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -1651,6 +1651,7 @@ static bool linux_sys_state_supports_mode(SuspendMode mode, Error **errp)
>      }
>  
>      ret = read(fd, buf, sizeof(buf) - 1);
> +    close(fd);
>      if (ret <= 0) {
>          return false;
>      }
>
Michael Roth July 16, 2018, 9:37 p.m. UTC | #2
Quoting Paolo Bonzini (2018-07-15 11:21:56)
> The file descriptor for /sys/power/state was never closed.  Reported
> by Coverity.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Thanks, applied to qga tree:
  https://github.com/mdroth/qemu/commits/qga

> ---
>  qga/commands-posix.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 233f78a406..4160aceaed 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -1651,6 +1651,7 @@ static bool linux_sys_state_supports_mode(SuspendMode mode, Error **errp)
>      }
> 
>      ret = read(fd, buf, sizeof(buf) - 1);
> +    close(fd);
>      if (ret <= 0) {
>          return false;
>      }
> -- 
> 2.17.1
>
diff mbox

Patch

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 233f78a406..4160aceaed 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -1651,6 +1651,7 @@  static bool linux_sys_state_supports_mode(SuspendMode mode, Error **errp)
     }
 
     ret = read(fd, buf, sizeof(buf) - 1);
+    close(fd);
     if (ret <= 0) {
         return false;
     }