]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
parallels: fix leaks in parallelsFindVolumes
authorDmitry Guryanov <dguryanov@parallels.com>
Tue, 4 Dec 2012 13:43:06 +0000 (17:43 +0400)
committerDaniel Veillard <veillard@redhat.com>
Tue, 11 Dec 2012 08:26:31 +0000 (16:26 +0800)
We always have to close opened dir and free 'path'.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
src/parallels/parallels_storage.c

index 148d870d3f73c5bc107b94aee95baf08d8f90746..0d59cce9d555270fcd3afbd6f539ac26d6292ad5 100644 (file)
@@ -86,13 +86,14 @@ parallelsFindVolumes(virStoragePoolObjPtr pool)
 {
     DIR *dir;
     struct dirent *ent;
-    char *path;
+    char *path = NULL;
+    int ret = -1;
 
     if (!(dir = opendir(pool->def->target.path))) {
         virReportSystemError(errno,
                              _("cannot open path '%s'"),
                              pool->def->target.path);
-        goto cleanup;
+        return -1;
     }
 
     while ((ent = readdir(dir)) != NULL) {
@@ -100,18 +101,21 @@ parallelsFindVolumes(virStoragePoolObjPtr pool)
             continue;
 
         if (!(path = virFileBuildPath(pool->def->target.path,
-                                      ent->d_name, NULL)))
-            goto no_memory;
+                                      ent->d_name, NULL))) {
+            virReportOOMError();
+            goto cleanup;
+        }
         if (!parallelsStorageVolumeDefine(pool, NULL, path, false))
             goto cleanup;
+
         VIR_FREE(path);
     }
 
-    return 0;
-no_memory:
-    virReportOOMError();
+    ret = 0;
 cleanup:
-    return -1;
+    VIR_FREE(path);
+    closedir(dir);
+    return ret;
 
 }