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.
virStorageNetProtocolTypeToString;
virStorageSourceAuthClear;
virStorageSourceClear;
+virStorageSourceClearBackingStore;
virStorageSourceFree;
virStorageSourceGetActualType;
virStorageSourcePoolDefFree;
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);
* 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;
}
+/**
+ * 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)
{
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);
}
void virStorageSourceClear(virStorageSourcePtr def);
int virStorageSourceGetActualType(virStorageSourcePtr def);
void virStorageSourceFree(virStorageSourcePtr def);
+void virStorageSourceClearBackingStore(virStorageSourcePtr def);
#endif /* __VIR_STORAGE_FILE_H__ */