提交 b4766823 编写于 作者: P Peter Krempa

storage: Clear all data allocated about backing store before reparsing

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 8823272d.
上级 cdebc2f7
......@@ -1865,6 +1865,7 @@ virStorageNetHostTransportTypeToString;
virStorageNetProtocolTypeToString;
virStorageSourceAuthClear;
virStorageSourceClear;
virStorageSourceClearBackingStore;
virStorageSourceFree;
virStorageSourceGetActualType;
virStorageSourcePoolDefFree;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -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__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册