Blob Blame History Raw
From: Daniel Veillard <veillard@redhat.com>
Date: Mon, 16 Mar 2009 10:41:37 +0000 (+0000)
Subject: Avoid some potential FILE * leaks
X-Git-Url: http://git.et.redhat.com/?p=libvirt.git;a=commitdiff_plain;h=39429bab2d55807698d9aed0112200ae532799b8

Avoid some potential FILE * leaks
* qemud/qemud.c src/cgroup.c src/uml_driver.c src/util.c: close
  some potential FILE * leaks
Daniel
---

diff --git a/qemud/qemud.c b/qemud/qemud.c
index fd315fc..4f04355 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -488,7 +488,7 @@ static int qemudWritePidFile(const char *pidFile) {
     if (fprintf(fh, "%lu\n", (unsigned long)getpid()) < 0) {
         VIR_ERROR(_("Failed to write to pid file '%s' : %s"),
                   pidFile, virStrerror(errno, ebuf, sizeof ebuf));
-        close(fd);
+        fclose(fh);
         return -1;
     }
 
diff --git a/src/cgroup.c b/src/cgroup.c
index 5af44bd..d1d44a2 100644
--- a/src/cgroup.c
+++ b/src/cgroup.c
@@ -57,7 +57,7 @@ void virCgroupFree(virCgroupPtr *group)
 
 static virCgroupPtr virCgroupGetMount(const char *controller)
 {
-    FILE *mounts;
+    FILE *mounts = NULL;
     struct mntent entry;
     char buf[CGROUP_MAX_VAL];
     virCgroupPtr root = NULL;
@@ -90,6 +90,8 @@ static virCgroupPtr virCgroupGetMount(const char *controller)
 
     return root;
 err:
+    if (mounts != NULL)
+        fclose(mounts);
     virCgroupFree(&root);
 
     return NULL;
diff --git a/src/uml_driver.c b/src/uml_driver.c
index 1dc7ccd..f7400f9 100644
--- a/src/uml_driver.c
+++ b/src/uml_driver.c
@@ -547,6 +547,7 @@ reopen:
 
     if (fscanf(file, "%d", &vm->pid) != 1) {
         errno = EINVAL;
+        fclose(file);
         goto cleanup;
     }
 
@@ -1040,6 +1041,7 @@ static int umlGetProcessInfo(unsigned long long *cpuTime, int pid) {
 
     if (fscanf(pidinfo, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu", &usertime, &systime) != 2) {
         umlDebug("not enough arg");
+        fclose(pidinfo);
         return -1;
     }
 
diff --git a/src/util.c b/src/util.c
index 9b74757..66ad9a4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1058,6 +1058,7 @@ int virFileReadPid(const char *dir,
 
     if (fscanf(file, "%d", pid) != 1) {
         rc = EINVAL;
+        fclose(file);
         goto cleanup;
     }