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 8823272d41.
This commit is contained in:
Peter Krempa 2014-04-26 08:27:58 +02:00
parent cdebc2f74c
commit b47668233e
5 changed files with 30 additions and 13 deletions

View File

@ -1865,6 +1865,7 @@ virStorageNetHostTransportTypeToString;
virStorageNetProtocolTypeToString;
virStorageSourceAuthClear;
virStorageSourceClear;
virStorageSourceClearBackingStore;
virStorageSourceFree;
virStorageSourceGetActualType;
virStorageSourcePoolDefFree;

View File

@ -2421,13 +2421,11 @@ 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);

View 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;

View 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);
}

View 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__ */