Patchwork libqtest: only call fclose() on open files

login
register
mail settings
Submitter Jesse Larrew
Date April 29, 2013, 3:52 p.m.
Message ID <1367250772-17928-1-git-send-email-jlarrew@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/240417/
State New
Headers show

Comments

Jesse Larrew - April 29, 2013, 3:52 p.m.
libqtest.c can segfault when calling fclose() if the pidfile wasn't
opened successfully. This patch fixes the issue.

Signed-off-by: Jesse Larrew <jlarrew@linux.vnet.ibm.com>
---
 tests/libqtest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Anthony Liguori - April 30, 2013, 2:51 p.m.
Jesse Larrew <jlarrew@linux.vnet.ibm.com> writes:

> libqtest.c can segfault when calling fclose() if the pidfile wasn't
> opened successfully. This patch fixes the issue.
>
> Signed-off-by: Jesse Larrew <jlarrew@linux.vnet.ibm.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>  tests/libqtest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 884f959..879ffe9 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -99,8 +99,8 @@ static pid_t qtest_qemu_pid(QTestState *s)
>          if (fgets(buffer, sizeof(buffer), f)) {
>              pid = atoi(buffer);
>          }
> +        fclose(f);
>      }
> -    fclose(f);
>      return pid;
>  }
>  
> -- 
> 1.7.11.7
Anthony Liguori - May 2, 2013, 3:55 p.m.
Applied.  Thanks.

Regards,

Anthony Liguori

Patch

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 884f959..879ffe9 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -99,8 +99,8 @@  static pid_t qtest_qemu_pid(QTestState *s)
         if (fgets(buffer, sizeof(buffer), f)) {
             pid = atoi(buffer);
         }
+        fclose(f);
     }
-    fclose(f);
     return pid;
 }