Using VIR_AUTOFREE() in all strings of qemu_driver.c make the code
a bit tidier and smaller, sparing VIR_FREE() calls and sometimes a
whole 'cleanup' label.
This is a huge change due to the amount of char * declared in
this file, thus let's split it in 3. This is the second part.
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_driver.c | 86 +++++++++++++++---------------------------
1 file changed, 30 insertions(+), 56 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f887a79ecd..f3fccc0843 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4108,11 +4108,11 @@ processWatchdogEvent(virQEMUDriverPtr driver,
{
int ret;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
- char *dumpfile = getAutoDumpPath(driver, vm);
+ VIR_AUTOFREE(char *) dumpfile = getAutoDumpPath(driver, vm);
unsigned int flags = VIR_DUMP_MEMORY_ONLY;
if (!dumpfile)
- goto cleanup;
+ return;
switch (action) {
case VIR_DOMAIN_WATCHDOG_ACTION_DUMP:
@@ -4120,7 +4120,7 @@ processWatchdogEvent(virQEMUDriverPtr driver,
QEMU_ASYNC_JOB_DUMP,
VIR_DOMAIN_JOB_OPERATION_DUMP,
flags) < 0) {
- goto cleanup;
+ return;
}
if (virDomainObjCheckActive(vm) < 0)
@@ -4141,14 +4141,11 @@ processWatchdogEvent(virQEMUDriverPtr driver,
"%s", _("Resuming after dump failed"));
break;
default:
- goto cleanup;
+ return;
}
endjob:
qemuDomainObjEndAsyncJob(driver, vm);
-
- cleanup:
- VIR_FREE(dumpfile);
}
static int
@@ -4158,18 +4155,16 @@ doCoreDumpToAutoDumpPath(virQEMUDriverPtr driver,
{
int ret = -1;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
- char *dumpfile = getAutoDumpPath(driver, vm);
+ VIR_AUTOFREE(char *) dumpfile = getAutoDumpPath(driver, vm);
if (!dumpfile)
- goto cleanup;
+ return -1;
flags |= cfg->autoDumpBypassCache ? VIR_DUMP_BYPASS_CACHE: 0;
if ((ret = doCoreDump(driver, vm, dumpfile, flags,
VIR_DOMAIN_CORE_DUMP_FORMAT_RAW)) < 0)
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("Dump failed"));
- cleanup:
- VIR_FREE(dumpfile);
return ret;
}
@@ -4179,14 +4174,11 @@ qemuProcessGuestPanicEventInfo(virQEMUDriverPtr driver,
virDomainObjPtr vm,
qemuMonitorEventPanicInfoPtr info)
{
- char *msg = qemuMonitorGuestPanicEventInfoFormatMsg(info);
- char *timestamp = virTimeStringNow();
+ VIR_AUTOFREE(char *) msg = qemuMonitorGuestPanicEventInfoFormatMsg(info);
+ VIR_AUTOFREE(char *) timestamp = virTimeStringNow();
if (msg && timestamp)
qemuDomainLogAppendMessage(driver, vm, "%s: panic %s\n", timestamp,
msg);
-
- VIR_FREE(timestamp);
- VIR_FREE(msg);
}
@@ -5082,7 +5074,7 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
virDomainVcpuDefPtr vcpuinfo;
qemuDomainObjPrivatePtr priv = vm->privateData;
virCgroupPtr cgroup_vcpu = NULL;
- char *str = NULL;
+ VIR_AUTOFREE(char *) str = NULL;
virObjectEventPtr event = NULL;
char paramField[VIR_TYPED_PARAM_FIELD_LENGTH] = "";
virTypedParameterPtr eventParams = NULL;
@@ -5146,7 +5138,6 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
cleanup:
virBitmapFree(tmpmap);
virCgroupFree(&cgroup_vcpu);
- VIR_FREE(str);
virObjectEventStateQueue(driver->domainEventState, event);
return ret;
}
@@ -5287,7 +5278,7 @@ qemuDomainPinEmulator(virDomainPtr dom,
virBitmapPtr pcpumap = NULL;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
virObjectEventPtr event = NULL;
- char *str = NULL;
+ VIR_AUTOFREE(char *) str = NULL;
virTypedParameterPtr eventParams = NULL;
int eventNparams = 0;
int eventMaxparams = 0;
@@ -5376,7 +5367,6 @@ qemuDomainPinEmulator(virDomainPtr dom,
if (cgroup_emulator)
virCgroupFree(&cgroup_emulator);
virObjectEventStateQueue(driver->domainEventState, event);
- VIR_FREE(str);
virBitmapFree(pcpumap);
virDomainObjEndAPI(&vm);
return ret;
@@ -5758,7 +5748,7 @@ qemuDomainPinIOThread(virDomainPtr dom,
virCgroupPtr cgroup_iothread = NULL;
virObjectEventPtr event = NULL;
char paramField[VIR_TYPED_PARAM_FIELD_LENGTH] = "";
- char *str = NULL;
+ VIR_AUTOFREE(char *) str = NULL;
virTypedParameterPtr eventParams = NULL;
int eventNparams = 0;
int eventMaxparams = 0;
@@ -5870,7 +5860,6 @@ qemuDomainPinIOThread(virDomainPtr dom,
if (cgroup_iothread)
virCgroupFree(&cgroup_iothread);
virObjectEventStateQueue(driver->domainEventState, event);
- VIR_FREE(str);
virBitmapFree(pcpumap);
virDomainObjEndAPI(&vm);
return ret;
@@ -5882,7 +5871,7 @@ qemuDomainHotplugAddIOThread(virQEMUDriverPtr driver,
unsigned int iothread_id)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
- char *alias = NULL;
+ VIR_AUTOFREE(char *) alias = NULL;
size_t idx;
int ret = -1;
unsigned int orig_niothreads = vm->def->niothreadids;
@@ -5958,7 +5947,6 @@ qemuDomainHotplugAddIOThread(virQEMUDriverPtr driver,
}
virDomainAuditIOThread(vm, orig_niothreads, new_niothreads,
"update", ret == 0);
- VIR_FREE(alias);
virJSONValueFree(props);
return ret;
@@ -6003,7 +5991,7 @@ qemuDomainHotplugDelIOThread(virQEMUDriverPtr driver,
{
qemuDomainObjPrivatePtr priv = vm->privateData;
size_t idx;
- char *alias = NULL;
+ VIR_AUTOFREE(char *) alias = NULL;
int rc = -1;
int ret = -1;
unsigned int orig_niothreads = vm->def->niothreadids;
@@ -6052,7 +6040,6 @@ qemuDomainHotplugDelIOThread(virQEMUDriverPtr driver,
}
virDomainAuditIOThread(vm, orig_niothreads, new_niothreads,
"update", rc == 0);
- VIR_FREE(alias);
return ret;
exit_monitor:
@@ -6822,7 +6809,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
virObjectEventPtr event;
int intermediatefd = -1;
virCommandPtr cmd = NULL;
- char *errbuf = NULL;
+ VIR_AUTOFREE(char *) errbuf = NULL;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
virQEMUSaveHeaderPtr header = &data->header;
VIR_AUTOUNREF(qemuDomainSaveCookiePtr) cookie = NULL;
@@ -6941,7 +6928,6 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
cleanup:
virCommandFree(cmd);
- VIR_FREE(errbuf);
if (qemuSecurityRestoreSavedStateLabel(driver, vm, path) < 0)
VIR_WARN("failed to restore save state label on %s", path);
return ret;
@@ -6957,7 +6943,7 @@ qemuDomainRestoreFlags(virConnectPtr conn,
qemuDomainObjPrivatePtr priv = NULL;
virDomainDefPtr def = NULL;
virDomainObjPtr vm = NULL;
- char *xmlout = NULL;
+ VIR_AUTOFREE(char *) xmlout = NULL;
const char *newxml = dxml;
int fd = -1;
int ret = -1;
@@ -7042,7 +7028,6 @@ qemuDomainRestoreFlags(virConnectPtr conn,
ret = -1;
virFileWrapperFdFree(wrapperFd);
virQEMUSaveDataFree(data);
- VIR_FREE(xmlout);
if (vm && ret < 0)
qemuDomainRemoveInactiveJob(driver, vm);
virDomainObjEndAPI(&vm);
@@ -7165,7 +7150,7 @@ qemuDomainManagedSaveGetXMLDesc(virDomainPtr dom, unsigned int
flags)
{
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm;
- char *path = NULL;
+ VIR_AUTOFREE(char *) path = NULL;
char *ret = NULL;
virDomainDefPtr def = NULL;
int fd = -1;
@@ -7202,7 +7187,6 @@ qemuDomainManagedSaveGetXMLDesc(virDomainPtr dom, unsigned int
flags)
virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
virDomainObjEndAPI(&vm);
- VIR_FREE(path);
return ret;
}
@@ -7213,7 +7197,7 @@ qemuDomainManagedSaveDefineXML(virDomainPtr dom, const char *dxml,
virQEMUDriverPtr driver = dom->conn->privateData;
virConnectPtr conn = dom->conn;
virDomainObjPtr vm;
- char *path = NULL;
+ VIR_AUTOFREE(char *) path = NULL;
int ret = -1;
if (!(vm = qemuDomainObjFromDomain(dom)))
@@ -7235,7 +7219,6 @@ qemuDomainManagedSaveDefineXML(virDomainPtr dom, const char *dxml,
cleanup:
virDomainObjEndAPI(&vm);
- VIR_FREE(path);
return ret;
}
@@ -7254,7 +7237,7 @@ qemuDomainObjRestore(virConnectPtr conn,
qemuDomainObjPrivatePtr priv = vm->privateData;
int fd = -1;
int ret = -1;
- char *xmlout = NULL;
+ VIR_AUTOFREE(char *) xmlout = NULL;
virQEMUSaveDataPtr data = NULL;
virFileWrapperFdPtr wrapperFd = NULL;
@@ -7311,7 +7294,6 @@ qemuDomainObjRestore(virConnectPtr conn,
cleanup:
virQEMUSaveDataFree(data);
- VIR_FREE(xmlout);
virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
if (virFileWrapperFdClose(wrapperFd) < 0)
@@ -7476,7 +7458,7 @@ qemuDomainObjStart(virConnectPtr conn,
qemuDomainAsyncJob asyncJob)
{
int ret = -1;
- char *managed_save;
+ VIR_AUTOFREE(char *) managed_save = NULL;
bool start_paused = (flags & VIR_DOMAIN_START_PAUSED) != 0;
bool autodestroy = (flags & VIR_DOMAIN_START_AUTODESTROY) != 0;
bool bypass_cache = (flags & VIR_DOMAIN_START_BYPASS_CACHE) != 0;
@@ -7494,7 +7476,7 @@ qemuDomainObjStart(virConnectPtr conn,
managed_save = qemuDomainManagedSavePath(driver, vm);
if (!managed_save)
- goto cleanup;
+ return ret;
if (virFileExists(managed_save)) {
if (force_boot) {
@@ -7502,7 +7484,7 @@ qemuDomainObjStart(virConnectPtr conn,
virReportSystemError(errno,
_("cannot remove managed save file %s"),
managed_save);
- goto cleanup;
+ return ret;
}
vm->hasManagedSave = false;
} else {
@@ -7518,11 +7500,11 @@ qemuDomainObjStart(virConnectPtr conn,
else
vm->hasManagedSave = false;
- goto cleanup;
+ return ret;
} else if (ret < 0) {
VIR_WARN("Unable to restore from managed state %s. "
"Maybe the file is corrupted?", managed_save);
- goto cleanup;
+ return ret;
} else {
VIR_WARN("Ignoring incomplete managed state %s",
managed_save);
priv->job.current->operation = op;
@@ -7549,8 +7531,6 @@ qemuDomainObjStart(virConnectPtr conn,
}
}
- cleanup:
- VIR_FREE(managed_save);
return ret;
}
@@ -7698,7 +7678,7 @@ qemuDomainUndefineFlags(virDomainPtr dom,
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm;
virObjectEventPtr event = NULL;
- char *name = NULL;
+ VIR_AUTOFREE(char *) name = NULL;
int ret = -1;
int nsnapshots;
int ncheckpoints;
@@ -7827,7 +7807,6 @@ qemuDomainUndefineFlags(virDomainPtr dom,
qemuDomainObjEndJob(driver, vm);
cleanup:
- VIR_FREE(name);
virDomainObjEndAPI(&vm);
virObjectEventStateQueue(driver->domainEventState, event);
return ret;
@@ -9165,7 +9144,8 @@ static int qemuDomainSetAutostart(virDomainPtr dom,
{
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm;
- char *configFile = NULL, *autostartLink = NULL;
+ VIR_AUTOFREE(char *) configFile = NULL;
+ VIR_AUTOFREE(char *) autostartLink = NULL;
int ret = -1;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
@@ -9229,8 +9209,6 @@ static int qemuDomainSetAutostart(virDomainPtr dom,
ret = 0;
cleanup:
- VIR_FREE(configFile);
- VIR_FREE(autostartLink);
virDomainObjEndAPI(&vm);
return ret;
}
@@ -10010,7 +9988,7 @@ qemuDomainSetNumaParamsLive(virDomainObjPtr vm,
{
virCgroupPtr cgroup_temp = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
- char *nodeset_str = NULL;
+ VIR_AUTOFREE(char *) nodeset_str = NULL;
virDomainNumatuneMemMode mode;
size_t i = 0;
int ret = -1;
@@ -10060,7 +10038,6 @@ qemuDomainSetNumaParamsLive(virDomainObjPtr vm,
ret = 0;
cleanup:
- VIR_FREE(nodeset_str);
virCgroupFree(&cgroup_temp);
return ret;
@@ -10203,7 +10180,7 @@ qemuDomainGetNumaParameters(virDomainPtr dom,
virDomainObjPtr vm = NULL;
virDomainNumatuneMemMode tmpmode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
qemuDomainObjPrivatePtr priv;
- char *nodeset = NULL;
+ VIR_AUTOFREE(char *) nodeset = NULL;
int ret = -1;
virDomainDefPtr def = NULL;
bool live = false;
@@ -10267,7 +10244,6 @@ qemuDomainGetNumaParameters(virDomainPtr dom,
ret = 0;
cleanup:
- VIR_FREE(nodeset);
virDomainObjEndAPI(&vm);
return ret;
}
@@ -11134,7 +11110,7 @@ qemuDomainBlockResize(virDomainPtr dom,
virDomainObjPtr vm;
qemuDomainObjPrivatePtr priv;
int ret = -1;
- char *device = NULL;
+ VIR_AUTOFREE(char *) device = NULL;
const char *nodename = NULL;
virDomainDiskDefPtr disk = NULL;
@@ -11206,7 +11182,6 @@ qemuDomainBlockResize(virDomainPtr dom,
qemuDomainObjEndJob(driver, vm);
cleanup:
- VIR_FREE(device);
virDomainObjEndAPI(&vm);
return ret;
}
@@ -11915,7 +11890,7 @@ qemuDomainBlockPeek(virDomainPtr dom,
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainDiskDefPtr disk = NULL;
virDomainObjPtr vm;
- char *tmpbuf = NULL;
+ VIR_AUTOFREE(char *) tmpbuf = NULL;
ssize_t nread;
int ret = -1;
@@ -11970,7 +11945,6 @@ qemuDomainBlockPeek(virDomainPtr dom,
if (disk)
virStorageFileDeinit(disk->src);
virDomainObjEndAPI(&vm);
- VIR_FREE(tmpbuf);
return ret;
}
--
2.21.0