[libvirt] [libvirt-sandbox][PATCH 2/4] libvirt-sandbox-init-common: Avoid calling fclose(NULL)

Michal Privoznik mprivozn at redhat.com
Wed Sep 23 09:15:22 UTC 2015


The problem occurs in setup_disk_tags. Imagine that fopen()
called at the beginning of the function fails. This results in
jumping onto the 'cleanup' label where fclose() is called.
However, at this point @fp is NULL. And fclose() does not like
that.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 libvirt-sandbox/libvirt-sandbox-init-common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c b/libvirt-sandbox/libvirt-sandbox-init-common.c
index 42beadc..af7e457 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -109,7 +109,8 @@ static gboolean setup_disk_tags(void) {
     }
     ret = TRUE;
  cleanup:
-    fclose(fp);
+    if (fp)
+        fclose(fp);
     return ret;
 }
 
-- 
2.4.9




More information about the libvir-list mailing list