]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Clear all data allocated about backing store before reparsing
authorPeter Krempa <pkrempa@redhat.com>
Sat, 26 Apr 2014 06:27:58 +0000 (08:27 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 30 Apr 2014 17:59:20 +0000 (19:59 +0200)
To avoid memory leak of the "backingStoreRaw" field when reparsing
backing chains a new function is being introduced by this patch that
shall be used to clear backing store information.

The memory leak was introduced in commit 8823272d41a259c1246c05d.

src/libvirt_private.syms
src/qemu/qemu_domain.c
src/qemu/qemu_driver.c
src/util/virstoragefile.c
src/util/virstoragefile.h

index 55b016d1874a7aaa8b3e478ceea26c4acfe1fcad..4cfaefc044d631b1993127e177e944a47e1b89e5 100644 (file)
@@ -1865,6 +1865,7 @@ virStorageNetHostTransportTypeToString;
 virStorageNetProtocolTypeToString;
 virStorageSourceAuthClear;
 virStorageSourceClear;
+virStorageSourceClearBackingStore;
 virStorageSourceFree;
 virStorageSourceGetActualType;
 virStorageSourcePoolDefFree;
index 8fa58f33ddd4212e6a3f1d8c16995d327629e967..a3c1b1c98d54aa28b176e0fabfdda6775ef84073 100644 (file)
@@ -2421,12 +2421,10 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
         goto cleanup;
 
     if (disk->src.backingStore) {
-        if (force) {
-            virStorageSourceFree(disk->src.backingStore);
-            disk->src.backingStore = NULL;
-        } else {
+        if (force)
+            virStorageSourceClearBackingStore(&disk->src);
+        else
             goto cleanup;
-        }
     }
 
     qemuDomainGetImageIds(cfg, vm, disk, &uid, &gid);
index 75cf8cb450d5c13bf44dc370dbab7ee95fa8f1f8..bf19c6e48ac7ce942625f4af8ed44b66e6654d14 100644 (file)
@@ -12734,8 +12734,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
      * recompute it.  Better would be storing the chain ourselves rather than
      * reprobing, but this requires modifying domain_conf and our XML to fully
      * track the chain across libvirtd restarts.  */
-    virStorageSourceFree(disk->src.backingStore);
-    disk->src.backingStore = NULL;
+    virStorageSourceClearBackingStore(&disk->src);
 
     if (virStorageFileInit(&snap->src) < 0)
         goto cleanup;
index dcce1ef13a78cafecccceba78cad0e72b719626a..5c43665731a864ba5757704599bde2424885d038 100644 (file)
@@ -1726,6 +1726,29 @@ virStorageSourceGetActualType(virStorageSourcePtr def)
 }
 
 
+/**
+ * virStorageSourceClearBackingStore:
+ *
+ * @src: disk source to clear
+ *
+ * Clears information about backing store of the current storage file.
+ */
+void
+virStorageSourceClearBackingStore(virStorageSourcePtr def)
+{
+    if (!def)
+        return;
+
+    VIR_FREE(def->relPath);
+    VIR_FREE(def->relDir);
+    VIR_FREE(def->backingStoreRaw);
+
+    /* recursively free backing chain */
+    virStorageSourceFree(def->backingStore);
+    def->backingStore = NULL;
+}
+
+
 void
 virStorageSourceClear(virStorageSourcePtr def)
 {
@@ -1755,12 +1778,7 @@ virStorageSourceClear(virStorageSourcePtr def)
     virStorageNetHostDefFree(def->nhosts, def->hosts);
     virStorageSourceAuthClear(def);
 
-    VIR_FREE(def->relPath);
-    VIR_FREE(def->relDir);
-    VIR_FREE(def->backingStoreRaw);
-
-    /* recursively free backing chain */
-    virStorageSourceFree(def->backingStore);
+    virStorageSourceClearBackingStore(def);
 }
 
 
index 148776ea8a4ce3877a5240b368566641fe5c90c9..9e6cdbaf5cf91c25db4dc296724b7742b0ab19b8 100644 (file)
@@ -316,5 +316,6 @@ void virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def);
 void virStorageSourceClear(virStorageSourcePtr def);
 int virStorageSourceGetActualType(virStorageSourcePtr def);
 void virStorageSourceFree(virStorageSourcePtr def);
+void virStorageSourceClearBackingStore(virStorageSourcePtr def);
 
 #endif /* __VIR_STORAGE_FILE_H__ */