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@xxxxxxxxx> --- 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 22c872e912..05736fbd26 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4103,11 +4103,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: @@ -4115,7 +4115,7 @@ processWatchdogEvent(virQEMUDriverPtr driver, QEMU_ASYNC_JOB_DUMP, VIR_DOMAIN_JOB_OPERATION_DUMP, flags) < 0) { - goto cleanup; + return; } if (virDomainObjCheckActive(vm) < 0) @@ -4136,14 +4136,11 @@ processWatchdogEvent(virQEMUDriverPtr driver, "%s", _("Resuming after dump failed")); break; default: - goto cleanup; + return; } endjob: qemuDomainObjEndAsyncJob(driver, vm); - - cleanup: - VIR_FREE(dumpfile); } static int @@ -4153,18 +4150,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; } @@ -4174,14 +4169,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); } @@ -5077,7 +5069,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; @@ -5141,7 +5133,6 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, cleanup: virBitmapFree(tmpmap); virCgroupFree(&cgroup_vcpu); - VIR_FREE(str); virObjectEventStateQueue(driver->domainEventState, event); return ret; } @@ -5282,7 +5273,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; @@ -5371,7 +5362,6 @@ qemuDomainPinEmulator(virDomainPtr dom, if (cgroup_emulator) virCgroupFree(&cgroup_emulator); virObjectEventStateQueue(driver->domainEventState, event); - VIR_FREE(str); virBitmapFree(pcpumap); virDomainObjEndAPI(&vm); return ret; @@ -5753,7 +5743,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; @@ -5865,7 +5855,6 @@ qemuDomainPinIOThread(virDomainPtr dom, if (cgroup_iothread) virCgroupFree(&cgroup_iothread); virObjectEventStateQueue(driver->domainEventState, event); - VIR_FREE(str); virBitmapFree(pcpumap); virDomainObjEndAPI(&vm); return ret; @@ -5877,7 +5866,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; @@ -5953,7 +5942,6 @@ qemuDomainHotplugAddIOThread(virQEMUDriverPtr driver, } virDomainAuditIOThread(vm, orig_niothreads, new_niothreads, "update", ret == 0); - VIR_FREE(alias); virJSONValueFree(props); return ret; @@ -5998,7 +5986,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; @@ -6047,7 +6035,6 @@ qemuDomainHotplugDelIOThread(virQEMUDriverPtr driver, } virDomainAuditIOThread(vm, orig_niothreads, new_niothreads, "update", rc == 0); - VIR_FREE(alias); return ret; exit_monitor: @@ -6817,7 +6804,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; @@ -6936,7 +6923,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; @@ -6952,7 +6938,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; @@ -7037,7 +7023,6 @@ qemuDomainRestoreFlags(virConnectPtr conn, ret = -1; virFileWrapperFdFree(wrapperFd); virQEMUSaveDataFree(data); - VIR_FREE(xmlout); if (vm && ret < 0) qemuDomainRemoveInactiveJob(driver, vm); virDomainObjEndAPI(&vm); @@ -7160,7 +7145,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; @@ -7197,7 +7182,6 @@ qemuDomainManagedSaveGetXMLDesc(virDomainPtr dom, unsigned int flags) virDomainDefFree(def); VIR_FORCE_CLOSE(fd); virDomainObjEndAPI(&vm); - VIR_FREE(path); return ret; } @@ -7208,7 +7192,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))) @@ -7230,7 +7214,6 @@ qemuDomainManagedSaveDefineXML(virDomainPtr dom, const char *dxml, cleanup: virDomainObjEndAPI(&vm); - VIR_FREE(path); return ret; } @@ -7249,7 +7232,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; @@ -7306,7 +7289,6 @@ qemuDomainObjRestore(virConnectPtr conn, cleanup: virQEMUSaveDataFree(data); - VIR_FREE(xmlout); virDomainDefFree(def); VIR_FORCE_CLOSE(fd); if (virFileWrapperFdClose(wrapperFd) < 0) @@ -7471,7 +7453,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; @@ -7489,7 +7471,7 @@ qemuDomainObjStart(virConnectPtr conn, managed_save = qemuDomainManagedSavePath(driver, vm); if (!managed_save) - goto cleanup; + return ret; if (virFileExists(managed_save)) { if (force_boot) { @@ -7497,7 +7479,7 @@ qemuDomainObjStart(virConnectPtr conn, virReportSystemError(errno, _("cannot remove managed save file %s"), managed_save); - goto cleanup; + return ret; } vm->hasManagedSave = false; } else { @@ -7513,11 +7495,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; @@ -7544,8 +7526,6 @@ qemuDomainObjStart(virConnectPtr conn, } } - cleanup: - VIR_FREE(managed_save); return ret; } @@ -7693,7 +7673,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; @@ -7814,7 +7794,6 @@ qemuDomainUndefineFlags(virDomainPtr dom, qemuDomainObjEndJob(driver, vm); cleanup: - VIR_FREE(name); virDomainObjEndAPI(&vm); virObjectEventStateQueue(driver->domainEventState, event); return ret; @@ -9152,7 +9131,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; @@ -9216,8 +9196,6 @@ static int qemuDomainSetAutostart(virDomainPtr dom, ret = 0; cleanup: - VIR_FREE(configFile); - VIR_FREE(autostartLink); virDomainObjEndAPI(&vm); return ret; } @@ -9997,7 +9975,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; @@ -10047,7 +10025,6 @@ qemuDomainSetNumaParamsLive(virDomainObjPtr vm, ret = 0; cleanup: - VIR_FREE(nodeset_str); virCgroupFree(&cgroup_temp); return ret; @@ -10190,7 +10167,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; @@ -10254,7 +10231,6 @@ qemuDomainGetNumaParameters(virDomainPtr dom, ret = 0; cleanup: - VIR_FREE(nodeset); virDomainObjEndAPI(&vm); return ret; } @@ -11121,7 +11097,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; @@ -11193,7 +11169,6 @@ qemuDomainBlockResize(virDomainPtr dom, qemuDomainObjEndJob(driver, vm); cleanup: - VIR_FREE(device); virDomainObjEndAPI(&vm); return ret; } @@ -11902,7 +11877,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; @@ -11957,7 +11932,6 @@ qemuDomainBlockPeek(virDomainPtr dom, if (disk) virStorageFileDeinit(disk->src); virDomainObjEndAPI(&vm); - VIR_FREE(tmpbuf); return ret; } -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list