qemu: Modernize memory cleaning in qemuDomainBlockCopyCommon

Use VIR_AUTOFREE, VIR_AUTOUNREF, and VIR_STEAL_PTR.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-05-14 14:30:57 +02:00
parent 019461facb
commit ddafae7a39

View File

@ -17572,7 +17572,7 @@ static int
qemuDomainBlockCopyCommon(virDomainObjPtr vm, qemuDomainBlockCopyCommon(virDomainObjPtr vm,
virConnectPtr conn, virConnectPtr conn,
const char *path, const char *path,
virStorageSourcePtr mirror, virStorageSourcePtr mirrorsrc,
unsigned long long bandwidth, unsigned long long bandwidth,
unsigned int granularity, unsigned int granularity,
unsigned long long buf_size, unsigned long long buf_size,
@ -17581,15 +17581,16 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
{ {
virQEMUDriverPtr driver = conn->privateData; virQEMUDriverPtr driver = conn->privateData;
qemuDomainObjPrivatePtr priv; qemuDomainObjPrivatePtr priv;
char *device = NULL; VIR_AUTOFREE(char *) device = NULL;
virDomainDiskDefPtr disk = NULL; virDomainDiskDefPtr disk = NULL;
int ret = -1; int ret = -1;
bool need_unlink = false; bool need_unlink = false;
virQEMUDriverConfigPtr cfg = NULL; VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
const char *format = NULL; const char *format = NULL;
virErrorPtr monitor_error = NULL; virErrorPtr monitor_error = NULL;
bool reuse = !!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT); bool reuse = !!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT);
qemuBlockJobDataPtr job = NULL; qemuBlockJobDataPtr job = NULL;
VIR_AUTOUNREF(virStorageSourcePtr) mirror = mirrorsrc;
/* Preliminaries: find the disk we are editing, sanity checks */ /* Preliminaries: find the disk we are editing, sanity checks */
virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW | virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW |
@ -17597,12 +17598,11 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB, -1); VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB, -1);
priv = vm->privateData; priv = vm->privateData;
cfg = virQEMUDriverGetConfig(driver);
if (virStorageSourceIsRelative(mirror)) { if (virStorageSourceIsRelative(mirror)) {
virReportError(VIR_ERR_INVALID_ARG, "%s", virReportError(VIR_ERR_INVALID_ARG, "%s",
_("absolute path must be used as block copy target")); _("absolute path must be used as block copy target"));
goto cleanup; return -1;
} }
if (bandwidth > LLONG_MAX) { if (bandwidth > LLONG_MAX) {
@ -17610,11 +17610,11 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
_("bandwidth must be less than " _("bandwidth must be less than "
"'%llu' bytes/s (%llu MiB/s)"), "'%llu' bytes/s (%llu MiB/s)"),
LLONG_MAX, LLONG_MAX >> 20); LLONG_MAX, LLONG_MAX >> 20);
goto cleanup; return -1;
} }
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
goto cleanup; return -1;
if (virDomainObjCheckActive(vm) < 0) if (virDomainObjCheckActive(vm) < 0)
goto endjob; goto endjob;
@ -17760,8 +17760,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
qemuBlockJobStarted(job); qemuBlockJobStarted(job);
need_unlink = false; need_unlink = false;
virStorageFileDeinit(mirror); virStorageFileDeinit(mirror);
disk->mirror = mirror; VIR_STEAL_PTR(disk->mirror, mirror);
mirror = NULL;
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY; disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY;
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
@ -17779,10 +17778,6 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
} }
qemuBlockJobStartupFinalize(job); qemuBlockJobStartupFinalize(job);
cleanup:
VIR_FREE(device);
virObjectUnref(cfg);
virObjectUnref(mirror);
return ret; return ret;
} }