Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_block.c | 3 +--
src/qemu/qemu_block.h | 3 +++
src/qemu/qemu_command.c | 14 +++++++-------
src/qemu/qemu_hotplug.c | 9 +++------
src/qemu/qemu_migration.c | 3 +--
5 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index cbf0aa4189..7961d31978 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -1543,7 +1543,7 @@
qemuBlockStorageSourceAttachDataFree(qemuBlockStorageSourceAttachDataPtr data)
qemuBlockStorageSourceAttachDataPtr
qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src)
{
- qemuBlockStorageSourceAttachDataPtr data;
+ VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data = NULL;
qemuBlockStorageSourceAttachDataPtr ret = NULL;
if (VIR_ALLOC(data) < 0)
@@ -1559,7 +1559,6 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr
src)
VIR_STEAL_PTR(ret, data);
cleanup:
- qemuBlockStorageSourceAttachDataFree(data);
return ret;
}
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 9401ab4e12..eab8da8e2c 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -102,6 +102,9 @@ struct qemuBlockStorageSourceAttachData {
void
qemuBlockStorageSourceAttachDataFree(qemuBlockStorageSourceAttachDataPtr data);
+VIR_DEFINE_AUTOPTR_FUNC(qemuBlockStorageSourceAttachData,
+ qemuBlockStorageSourceAttachDataFree);
+
qemuBlockStorageSourceAttachDataPtr
qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src);
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 029780fe86..7d439550f3 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2554,7 +2554,7 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd,
{
qemuBlockStorageSourceAttachDataPtr *data = NULL;
size_t ndata = 0;
- qemuBlockStorageSourceAttachDataPtr tmp = NULL;
+ VIR_AUTOPTR(qemuBlockStorageSourceAttachData) tmp = NULL;
virJSONValuePtr copyOnReadProps = NULL;
virStorageSourcePtr n;
char *str = NULL;
@@ -2613,7 +2613,6 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd,
for (i = 0; i < ndata; i++)
qemuBlockStorageSourceAttachDataFree(data[i]);
VIR_FREE(data);
- qemuBlockStorageSourceAttachDataFree(tmp);
virJSONValueFree(copyOnReadProps);
VIR_FREE(str);
return ret;
@@ -11160,18 +11159,19 @@ qemuBlockStorageSourceAttachDataPtr
qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk,
virQEMUCapsPtr qemuCaps)
{
- qemuBlockStorageSourceAttachDataPtr data = NULL;
+ VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data = NULL;
+ qemuBlockStorageSourceAttachDataPtr ret = NULL;
if (VIR_ALLOC(data) < 0)
return NULL;
if (!(data->driveCmd = qemuBuildDriveStr(disk, qemuCaps)) ||
- !(data->driveAlias = qemuAliasDiskDriveFromDisk(disk))) {
- qemuBlockStorageSourceAttachDataFree(data);
+ !(data->driveAlias = qemuAliasDiskDriveFromDisk(disk)))
return NULL;
- }
- return data;
+ VIR_STEAL_PTR(ret, data);
+
+ return ret;
}
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 34249bd030..90c6a108dc 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -530,7 +530,7 @@ qemuHotplugRemoveStorageSourcePrepareData(virStorageSourcePtr src,
{
qemuDomainStorageSourcePrivatePtr srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
- qemuBlockStorageSourceAttachDataPtr data;
+ VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data = NULL;
qemuBlockStorageSourceAttachDataPtr ret = NULL;
if (VIR_ALLOC(data) < 0)
@@ -570,7 +570,6 @@ qemuHotplugRemoveStorageSourcePrepareData(virStorageSourcePtr src,
cleanup:
VIR_FREE(driveAlias);
- qemuBlockStorageSourceAttachDataFree(data);
return ret;
}
@@ -581,7 +580,7 @@ qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
virQEMUCapsPtr qemuCaps)
{
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
- qemuBlockStorageSourceAttachDataPtr backend = NULL;
+ VIR_AUTOPTR(qemuBlockStorageSourceAttachData) backend = NULL;
qemuHotplugDiskSourceDataPtr data = NULL;
qemuHotplugDiskSourceDataPtr ret = NULL;
char *drivealias = NULL;
@@ -616,7 +615,6 @@ qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
VIR_STEAL_PTR(ret, data);
cleanup:
- qemuBlockStorageSourceAttachDataFree(backend);
qemuHotplugDiskSourceDataFree(data);
return ret;
}
@@ -636,7 +634,7 @@ qemuHotplugDiskSourceAttachPrepare(virDomainDiskDefPtr disk,
virStorageSourcePtr src,
virQEMUCapsPtr qemuCaps)
{
- qemuBlockStorageSourceAttachDataPtr backend = NULL;
+ VIR_AUTOPTR(qemuBlockStorageSourceAttachData) backend = NULL;
qemuHotplugDiskSourceDataPtr data;
qemuHotplugDiskSourceDataPtr ret = NULL;
virStorageSourcePtr savesrc = NULL;
@@ -682,7 +680,6 @@ qemuHotplugDiskSourceAttachPrepare(virDomainDiskDefPtr disk,
if (savesrc)
VIR_STEAL_PTR(disk->src, savesrc);
- qemuBlockStorageSourceAttachDataFree(backend);
qemuHotplugDiskSourceDataFree(data);
return ret;
}
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 5db23b492f..a8d50d310d 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -787,7 +787,7 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver,
unsigned int mirror_flags,
const char *tlsAlias)
{
- qemuBlockStorageSourceAttachDataPtr data = NULL;
+ VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data = NULL;
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
int mon_ret = 0;
int ret = -1;
@@ -849,7 +849,6 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver,
ret = 0;
cleanup:
- qemuBlockStorageSourceAttachDataFree(data);
return ret;
}
--
2.20.1