[libvirt PATCH 0/9] qemu: use g_new0 (glib chronicles)

With the exception of qemu_migrate_cookie and qemu_slirp which should be dealt with by Peter's series. Ján Tomko (9): qemu: separate out VIR_ALLOC calls qemu: capabilities: use g_new0 qemu: domain: use g_new0 qemu: driver: use g_new0 qemu: monitor: json: use g_new0 qemu: process: use g_new0 qemu: command: use g_new0 qemu: firmware: use g_new0 qemu: use g_new0 src/qemu/qemu_agent.c | 6 +- src/qemu/qemu_block.c | 15 ++--- src/qemu/qemu_capabilities.c | 48 +++++--------- src/qemu/qemu_cgroup.c | 6 +- src/qemu/qemu_command.c | 35 ++++------- src/qemu/qemu_conf.c | 20 +++--- src/qemu/qemu_domain.c | 55 ++++++---------- src/qemu/qemu_domain_address.c | 3 +- src/qemu/qemu_driver.c | 62 +++++++----------- src/qemu/qemu_firmware.c | 34 ++++------ src/qemu/qemu_hotplug.c | 29 ++++----- src/qemu/qemu_migration.c | 6 +- src/qemu/qemu_monitor.c | 13 +--- src/qemu/qemu_monitor_json.c | 112 +++++++++++---------------------- src/qemu/qemu_namespace.c | 3 +- src/qemu/qemu_process.c | 75 +++++++++------------- src/qemu/qemu_saveimage.c | 3 +- src/qemu/qemu_vhost_user.c | 17 +++-- 18 files changed, 190 insertions(+), 352 deletions(-) -- 2.26.2

Move them to separate conditions to reduce churn in following patches. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_domain.c | 6 ++++-- src/qemu/qemu_monitor_json.c | 6 ++++-- src/qemu/qemu_process.c | 23 ++++++++++++----------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0331fd55e0..491fb0ed3d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3719,8 +3719,10 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def, if (j == def->npanics) { virDomainPanicDefPtr panic; - if (VIR_ALLOC(panic) < 0 || - VIR_APPEND_ELEMENT_COPY(def->panics, + if (VIR_ALLOC(panic) < 0) + return -1; + + if (VIR_APPEND_ELEMENT_COPY(def->panics, def->npanics, panic) < 0) { VIR_FREE(panic); return -1; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index bc242c798b..c399100dbe 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4890,8 +4890,10 @@ qemuMonitorJSONParseBlockJobInfo(virHashTablePtr blockJobs, if (!rawjobname) device = qemuAliasDiskDriveSkipPrefix(device); - if (VIR_ALLOC(info) < 0 || - virHashAddEntry(blockJobs, device, info) < 0) { + if (VIR_ALLOC(info) < 0) + return -1; + + if (virHashAddEntry(blockJobs, device, info) < 0) { VIR_FREE(info); return -1; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 9122069cc9..93cbb37986 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -832,17 +832,18 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon G_GNUC_UNUSED, if (vm->def->watchdog->action == VIR_DOMAIN_WATCHDOG_ACTION_DUMP) { struct qemuProcessEvent *processEvent; - if (VIR_ALLOC(processEvent) == 0) { - processEvent->eventType = QEMU_PROCESS_EVENT_WATCHDOG; - processEvent->action = VIR_DOMAIN_WATCHDOG_ACTION_DUMP; - /* Hold an extra reference because we can't allow 'vm' to be - * deleted before handling watchdog event is finished. - */ - processEvent->vm = virObjectRef(vm); - if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) { - virObjectUnref(vm); - qemuProcessEventFree(processEvent); - } + if (VIR_ALLOC(processEvent) < 0) + ; + + processEvent->eventType = QEMU_PROCESS_EVENT_WATCHDOG; + processEvent->action = VIR_DOMAIN_WATCHDOG_ACTION_DUMP; + /* Hold an extra reference because we can't allow 'vm' to be + * deleted before handling watchdog event is finished. + */ + processEvent->vm = virObjectRef(vm); + if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) { + virObjectUnref(vm); + qemuProcessEventFree(processEvent); } } -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_capabilities.c | 48 ++++++++++++------------------------ 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 5dcfcd574d..2e0e4492a4 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -943,14 +943,12 @@ virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps, *machines = NULL; *nmachines = accel->nmachineTypes; - if (*nmachines && - VIR_ALLOC_N(*machines, accel->nmachineTypes) < 0) - goto error; + if (*nmachines) + *machines = g_new0(virCapsGuestMachinePtr, accel->nmachineTypes); for (i = 0; i < accel->nmachineTypes; i++) { virCapsGuestMachinePtr mach; - if (VIR_ALLOC(mach) < 0) - goto error; + mach = g_new0(virCapsGuestMachine, 1); (*machines)[i] = mach; if (accel->machineTypes[i].alias) { mach->name = g_strdup(accel->machineTypes[i].alias); @@ -985,8 +983,7 @@ virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps, if (!found) { virCapsGuestMachinePtr mach; - if (VIR_ALLOC(mach) < 0) - goto error; + mach = g_new0(virCapsGuestMachine, 1); if (VIR_INSERT_ELEMENT_COPY(*machines, i, *nmachines, mach) < 0) { VIR_FREE(mach); goto error; @@ -1868,8 +1865,7 @@ virQEMUCapsSEVInfoCopy(virSEVCapabilityPtr *dst, { g_autoptr(virSEVCapability) tmp = NULL; - if (VIR_ALLOC(tmp) < 0) - return -1; + tmp = g_new0(virSEVCapability, 1); tmp->pdh = g_strdup(src->pdh); tmp->cert_chain = g_strdup(src->cert_chain); @@ -1949,8 +1945,7 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps) virQEMUCapsAccelCopy(&ret->tcg, &qemuCaps->tcg) < 0) goto error; - if (VIR_ALLOC_N(ret->gicCapabilities, qemuCaps->ngicCapabilities) < 0) - goto error; + ret->gicCapabilities = g_new0(virGICCapability, qemuCaps->ngicCapabilities); ret->ngicCapabilities = qemuCaps->ngicCapabilities; for (i = 0; i < qemuCaps->ngicCapabilities; i++) ret->gicCapabilities[i] = qemuCaps->gicCapabilities[i]; @@ -3184,8 +3179,7 @@ virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps, if (!modelInfo) return 0; - if (VIR_ALLOC_N(list, modelInfo->nprops + 1) < 0) - return -1; + list = g_new0(char *, modelInfo->nprops + 1); n = 0; for (i = 0; i < modelInfo->nprops; i++) { @@ -3561,8 +3555,7 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps, } cpu->model = g_strdup(modelInfo->name); - if (VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0) - return -1; + cpu->features = g_new0(virCPUFeatureDef, modelInfo->nprops); cpu->nfeatures_max = modelInfo->nprops; cpu->nfeatures = 0; @@ -3872,8 +3865,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccelPtr caps, goto cleanup; } - if (VIR_ALLOC(hostCPU) < 0) - goto cleanup; + hostCPU = g_new0(qemuMonitorCPUModelInfo, 1); if (!(hostCPU->name = virXMLPropString(hostCPUNode, "model"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -3894,9 +3886,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccelPtr caps, ctxt->node = hostCPUNode; if ((n = virXPathNodeSet("./property", ctxt, &nodes)) > 0) { - if (VIR_ALLOC_N(hostCPU->props, n) < 0) - goto cleanup; - + hostCPU->props = g_new0(qemuMonitorCPUProperty, n); hostCPU->nprops = n; for (i = 0; i < n; i++) { @@ -4041,8 +4031,7 @@ virQEMUCapsLoadCPUModels(virQEMUCapsAccelPtr caps, if (nblockers > 0) { size_t j; - if (VIR_ALLOC_N(cpu->blockers, nblockers + 1) < 0) - return -1; + cpu->blockers = g_new0(char *, nblockers + 1); for (j = 0; j < nblockers; j++) { if (!(cpu->blockers[j] = virXMLPropString(blockerNodes[j], "name"))) { @@ -4081,8 +4070,7 @@ virQEMUCapsLoadMachines(virQEMUCapsAccelPtr caps, return 0; caps->nmachineTypes = n; - if (VIR_ALLOC_N(caps->machineTypes, caps->nmachineTypes) < 0) - return -1; + caps->machineTypes = g_new0(virQEMUCapsMachineType, caps->nmachineTypes); for (i = 0; i < n; i++) { if (!(caps->machineTypes[i].name = virXMLPropString(nodes[i], "name"))) { @@ -4189,8 +4177,7 @@ virQEMUCapsParseSEVInfo(virQEMUCapsPtr qemuCaps, xmlXPathContextPtr ctxt) return -1; } - if (VIR_ALLOC(sev) < 0) - return -1; + sev = g_new0(virSEVCapability, 1); if (virXPathUInt("string(./sev/cbitpos)", ctxt, &sev->cbitpos) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -4408,8 +4395,7 @@ virQEMUCapsLoadCache(virArch hostArch, bool boolValue; qemuCaps->ngicCapabilities = n; - if (VIR_ALLOC_N(qemuCaps->gicCapabilities, n) < 0) - goto cleanup; + qemuCaps->gicCapabilities = g_new0(virGICCapability, n); for (i = 0; i < n; i++) { virGICCapabilityPtr cap = &qemuCaps->gicCapabilities[i]; @@ -5674,8 +5660,7 @@ virQEMUCapsCacheNew(const char *libDir, if (!(cache = virFileCacheNew(capsCacheDir, "xml", &qemuCapsCacheHandlers))) goto error; - if (VIR_ALLOC(priv) < 0) - goto error; + priv = g_new0(virQEMUCapsCachePriv, 1); virFileCacheSetPriv(cache, priv); priv->libDir = g_strdup(libDir); @@ -5899,8 +5884,7 @@ virQEMUCapsFillDomainLoaderCaps(virDomainCapsLoaderPtr capsLoader, capsLoader->readonly.report = true; capsLoader->secure.report = true; - if (VIR_ALLOC_N(capsLoader->values.values, nfirmwares) < 0) - return -1; + capsLoader->values.values = g_new0(char *, nfirmwares); for (i = 0; i < nfirmwares; i++) { const char *filename = firmwares[i]->name; -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_domain.c | 53 ++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 491fb0ed3d..15912317de 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -496,8 +496,7 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv) goto error; } - if (VIR_ALLOC_N(masterKey, 1024) < 0) - goto error; + masterKey = g_new0(uint8_t, 1024); if ((masterKeyLen = saferead(fd, masterKey, 1024)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -572,8 +571,7 @@ qemuDomainMasterKeyCreate(virDomainObjPtr vm) if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_OBJECT_SECRET)) return 0; - if (VIR_ALLOC_N(priv->masterKey, QEMU_DOMAIN_MASTER_KEY_LEN) < 0) - return -1; + priv->masterKey = g_new0(uint8_t, QEMU_DOMAIN_MASTER_KEY_LEN); priv->masterKeyLen = QEMU_DOMAIN_MASTER_KEY_LEN; if (virRandomBytes(priv->masterKey, priv->masterKeyLen) < 0) { @@ -1188,8 +1186,7 @@ qemuDomainSecretInfoNewPlain(virSecretUsageType usageType, { qemuDomainSecretInfoPtr secinfo = NULL; - if (VIR_ALLOC(secinfo) < 0) - return NULL; + secinfo = g_new0(qemuDomainSecretInfo, 1); if (qemuDomainSecretPlainSetup(secinfo, usageType, username, lookupDef) < 0) { g_clear_pointer(&secinfo, qemuDomainSecretInfoFree); @@ -1689,8 +1686,7 @@ qemuDomainObjPrivateAlloc(void *opaque) { qemuDomainObjPrivatePtr priv; - if (VIR_ALLOC(priv) < 0) - return NULL; + priv = g_new0(qemuDomainObjPrivate, 1); if (qemuDomainObjInitJob(&priv->job, &qemuPrivateJobCallbacks) < 0) { virReportSystemError(errno, "%s", @@ -1845,9 +1841,7 @@ qemuStorageSourcePrivateDataAssignSecinfo(qemuDomainSecretInfoPtr *secinfo, return 0; if (!*secinfo) { - if (VIR_ALLOC(*secinfo) < 0) - return -1; - + *secinfo = g_new0(qemuDomainSecretInfo, 1); (*secinfo)->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES; } @@ -3083,8 +3077,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, } if (n > 0) { /* NULL-terminated list */ - if (VIR_ALLOC_N(priv->qemuDevices, n + 1) < 0) - goto error; + priv->qemuDevices = g_new0(char *, n + 1); for (i = 0; i < n; i++) { priv->qemuDevices[i] = virXMLPropString(nodes[i], "alias"); @@ -3245,8 +3238,7 @@ qemuDomainDefNamespaceParseCommandlineArgs(qemuDomainXmlNsDefPtr nsdef, if (nnodes == 0) return 0; - if (VIR_ALLOC_N(nsdef->args, nnodes) < 0) - return -1; + nsdef->args = g_new0(char *, nnodes); for (i = 0; i < nnodes; i++) { if (!(nsdef->args[nsdef->num_args++] = virXMLPropString(nodes[i], "value"))) { @@ -3293,9 +3285,8 @@ qemuDomainDefNamespaceParseCommandlineEnv(qemuDomainXmlNsDefPtr nsdef, if (nnodes == 0) return 0; - if (VIR_ALLOC_N(nsdef->env_name, nnodes) < 0 || - VIR_ALLOC_N(nsdef->env_value, nnodes) < 0) - return -1; + nsdef->env_name = g_new0(char *, nnodes); + nsdef->env_value = g_new0(char *, nnodes); for (i = 0; i < nnodes; i++) { if (!(nsdef->env_name[nsdef->num_env] = virXMLPropString(nodes[i], "name"))) { @@ -3331,8 +3322,7 @@ qemuDomainDefNamespaceParseCaps(qemuDomainXmlNsDefPtr nsdef, return -1; if (nnodesadd > 0) { - if (VIR_ALLOC_N(nsdef->capsadd, nnodesadd) < 0) - return -1; + nsdef->capsadd = g_new0(char *, nnodesadd); for (i = 0; i < nnodesadd; i++) { if (!(nsdef->capsadd[nsdef->ncapsadd++] = virXMLPropString(nodesadd[i], "capability"))) { @@ -3344,8 +3334,7 @@ qemuDomainDefNamespaceParseCaps(qemuDomainXmlNsDefPtr nsdef, } if (nnodesdel > 0) { - if (VIR_ALLOC_N(nsdef->capsdel, nnodesdel) < 0) - return -1; + nsdef->capsdel = g_new0(char *, nnodesdel); for (i = 0; i < nnodesdel; i++) { if (!(nsdef->capsdel[nsdef->ncapsdel++] = virXMLPropString(nodesdel[i], "capability"))) { @@ -3367,8 +3356,7 @@ qemuDomainDefNamespaceParse(xmlXPathContextPtr ctxt, qemuDomainXmlNsDefPtr nsdata = NULL; int ret = -1; - if (VIR_ALLOC(nsdata) < 0) - return -1; + nsdata = g_new0(qemuDomainXmlNsDef, 1); if (qemuDomainDefNamespaceParseCommandlineArgs(nsdata, ctxt) < 0 || qemuDomainDefNamespaceParseCommandlineEnv(nsdata, ctxt) < 0 || @@ -3661,8 +3649,7 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def, if (addDefaultMemballoon && !def->memballoon) { virDomainMemballoonDefPtr memballoon; - if (VIR_ALLOC(memballoon) < 0) - return -1; + memballoon = g_new0(virDomainMemballoonDef, 1); memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO; def->memballoon = memballoon; @@ -3718,9 +3705,7 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def, } if (j == def->npanics) { - virDomainPanicDefPtr panic; - if (VIR_ALLOC(panic) < 0) - return -1; + virDomainPanicDefPtr panic = g_new0(virDomainPanicDef, 1); if (VIR_APPEND_ELEMENT_COPY(def->panics, def->npanics, panic) < 0) { @@ -5911,12 +5896,9 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver, virDomainControllerDefPtr *controllers = def->controllers; int ncontrollers = def->ncontrollers; - if (VIR_ALLOC_N(def->controllers, ncontrollers - toremove) < 0) { - def->controllers = controllers; - goto cleanup; - } - + def->controllers = g_new0(virDomainControllerDefPtr, ncontrollers - toremove); def->ncontrollers = 0; + for (i = 0; i < ncontrollers; i++) { if (controllers[i] != usb && controllers[i] != pci) def->controllers[def->ncontrollers++] = controllers[i]; @@ -6347,8 +6329,7 @@ ssize_t qemuDomainLogContextRead(qemuDomainLogContextPtr ctxt, /* Best effort jump to start of messages */ ignore_value(lseek(ctxt->readfd, ctxt->pos, SEEK_SET)); - if (VIR_ALLOC_N(buf, buflen) < 0) - return -1; + buf = g_new0(char, buflen); got = saferead(ctxt->readfd, buf, buflen - 1); if (got < 0) { -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_driver.c | 62 ++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 85b6a6a321..e622da56bd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -625,8 +625,7 @@ qemuStateInitialize(bool privileged, const char *defsecmodel = NULL; g_autofree virSecurityManagerPtr *sec_managers = NULL; - if (VIR_ALLOC(qemu_driver) < 0) - return VIR_DRV_STATE_INIT_ERROR; + qemu_driver = g_new0(virQEMUDriver, 1); qemu_driver->lockFD = -1; @@ -1059,8 +1058,7 @@ qemuStateStop(void) VIR_CONNECT_LIST_DOMAINS_ACTIVE)) < 0) goto cleanup; - if (VIR_ALLOC_N(flags, numDomains) < 0) - goto cleanup; + flags = g_new0(unsigned int, numDomains); /* First we pause all VMs to make them stop dirtying pages, etc. We remember if any VMs were paused so @@ -5043,14 +5041,12 @@ qemuDomainGetIOThreadsLive(virQEMUDriverPtr driver, goto endjob; } - if (VIR_ALLOC_N(info_ret, niothreads) < 0) - goto endjob; + info_ret = g_new0(virDomainIOThreadInfoPtr, niothreads); for (i = 0; i < niothreads; i++) { virBitmapPtr map = NULL; - if (VIR_ALLOC(info_ret[i]) < 0) - goto endjob; + info_ret[i] = g_new0(virDomainIOThreadInfo, 1); info_ret[i]->iothread_id = iothreads[i]->iothread_id; if (!(map = virProcessGetAffinity(iothreads[i]->thread_id))) @@ -5098,12 +5094,10 @@ qemuDomainGetIOThreadsConfig(virDomainDefPtr targetDef, if (targetDef->niothreadids == 0) return 0; - if (VIR_ALLOC_N(info_ret, targetDef->niothreadids) < 0) - goto cleanup; + info_ret = g_new0(virDomainIOThreadInfoPtr, targetDef->niothreadids); for (i = 0; i < targetDef->niothreadids; i++) { - if (VIR_ALLOC(info_ret[i]) < 0) - goto cleanup; + info_ret[i] = g_new0(virDomainIOThreadInfo, 1); /* IOThread ID's are taken from the iothreadids list */ info_ret[i]->iothread_id = targetDef->iothreadids[i]->iothread_id; @@ -5945,10 +5939,7 @@ static int qemuDomainGetSecurityLabelList(virDomainPtr dom, for (i = 0; mgrs[i]; i++) len++; - if (VIR_ALLOC_N((*seclabels), len) < 0) { - VIR_FREE(mgrs); - goto cleanup; - } + (*seclabels) = g_new0(virSecurityLabel, len); memset(*seclabels, 0, sizeof(**seclabels) * len); /* Fill the array */ @@ -9979,8 +9970,7 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver, if (qemuDomainObjExitMonitor(driver, vm) < 0 || nstats < 0 || rc < 0) goto cleanup; - if (VIR_ALLOC(*retstats) < 0) - goto cleanup; + *retstats = g_new0(qemuBlockStats, 1); if (entryname) { if (!(stats = virHashLookup(blockstats, entryname))) { @@ -10284,10 +10274,9 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, goto endjob; } - if ((VIR_ALLOC(bandwidth) < 0) || - (VIR_ALLOC(bandwidth->in) < 0) || - (VIR_ALLOC(bandwidth->out) < 0)) - goto endjob; + bandwidth = g_new0(virNetDevBandwidth, 1); + bandwidth->in = g_new0(virNetDevBandwidthRate, 1); + bandwidth->out = g_new0(virNetDevBandwidthRate, 1); for (i = 0; i < nparams; i++) { virTypedParameterPtr param = ¶ms[i]; @@ -10321,16 +10310,14 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, VIR_FREE(bandwidth->out); if (net) { - if (VIR_ALLOC(newBandwidth) < 0) - goto endjob; + newBandwidth = g_new0(virNetDevBandwidth, 1); /* virNetDevBandwidthSet() will clear any previous value of * bandwidth parameters, so merge with old bandwidth parameters * here to prevent them from being lost. */ if (bandwidth->in || (!inboundSpecified && net->bandwidth && net->bandwidth->in)) { - if (VIR_ALLOC(newBandwidth->in) < 0) - goto endjob; + newBandwidth->in = g_new0(virNetDevBandwidthRate, 1); memcpy(newBandwidth->in, bandwidth->in ? bandwidth->in : net->bandwidth->in, @@ -10338,8 +10325,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, } if (bandwidth->out || (!outboundSpecified && net->bandwidth && net->bandwidth->out)) { - if (VIR_ALLOC(newBandwidth->out) < 0) - goto endjob; + newBandwidth->out = g_new0(virNetDevBandwidthRate, 1); memcpy(newBandwidth->out, bandwidth->out ? bandwidth->out : net->bandwidth->out, @@ -12463,8 +12449,7 @@ qemuConnectCPUModelBaseline(virQEMUCapsPtr qemuCaps, if (qemuProcessQMPStart(proc) < 0) return NULL; - if (VIR_ALLOC(baseline) < 0) - return NULL; + baseline = g_new0(virCPUDef, 1); if (virCPUDefCopyModel(baseline, cpus[0], false)) return NULL; @@ -17721,8 +17706,7 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr driver, if (domresmon->tag != tag) continue; - if (VIR_ALLOC(res) < 0) - return -1; + res = g_new0(virQEMUResctrlMonData, 1); /* If virBitmapFormat successfully returns an vcpu string, then * res.vcpus is assigned with an memory space holding it, @@ -18036,9 +18020,8 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver, "vcpu.maximum") < 0) return -1; - if (VIR_ALLOC_N(cpuinfo, virDomainDefGetVcpus(dom->def)) < 0 || - VIR_ALLOC_N(cpuwait, virDomainDefGetVcpus(dom->def)) < 0) - goto cleanup; + cpuinfo = g_new0(virVcpuInfo, virDomainDefGetVcpus(dom->def)); + cpuwait = g_new0(unsigned long long, virDomainDefGetVcpus(dom->def)); if (HAVE_JOB(privflags) && virDomainObjIsActive(dom) && qemuDomainRefreshVcpuHalted(driver, dom, QEMU_ASYNC_JOB_NONE) < 0) { @@ -18690,8 +18673,7 @@ qemuDomainGetStats(virConnectPtr conn, g_autoptr(virTypedParamList) params = NULL; size_t i; - if (VIR_ALLOC(params) < 0) - return -1; + params = g_new0(virTypedParamList, 1); for (i = 0; qemuDomainGetStatsWorkers[i].func; i++) { if (stats & qemuDomainGetStatsWorkers[i].stats) { @@ -18701,8 +18683,7 @@ qemuDomainGetStats(virConnectPtr conn, } } - if (VIR_ALLOC(tmp) < 0) - return -1; + tmp = g_new0(virDomainStatsRecord, 1); if (!(tmp->dom = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id))) @@ -18763,8 +18744,7 @@ qemuConnectGetAllDomainStats(virConnectPtr conn, return -1; } - if (VIR_ALLOC_N(tmpstats, nvms + 1) < 0) - goto cleanup; + tmpstats = g_new0(virDomainStatsRecordPtr, nvms + 1); if (qemuDomainGetStatsNeedMonitor(stats)) privflags |= QEMU_DOMAIN_STATS_HAVE_JOB; -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_monitor_json.c | 110 ++++++++++++----------------------- 1 file changed, 36 insertions(+), 74 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index c399100dbe..26ac499fc5 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -769,8 +769,7 @@ qemuMonitorJSONGuestPanicExtractInfoHyperv(virJSONValuePtr data) { qemuMonitorEventPanicInfoPtr ret; - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(qemuMonitorEventPanicInfo, 1); ret->type = QEMU_MONITOR_EVENT_PANIC_INFO_TYPE_HYPERV; @@ -799,8 +798,7 @@ qemuMonitorJSONGuestPanicExtractInfoS390(virJSONValuePtr data) unsigned long long psw_mask, psw_addr; const char *reason = NULL; - if (VIR_ALLOC(ret) < 0) - return NULL; + ret = g_new0(qemuMonitorEventPanicInfo, 1); ret->type = QEMU_MONITOR_EVENT_PANIC_INFO_TYPE_S390; @@ -1900,8 +1898,7 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data, if ((ncpus = virJSONValueArraySize(data)) == 0) return -2; - if (VIR_ALLOC_N(cpus, ncpus) < 0) - goto cleanup; + cpus = g_new0(struct qemuMonitorQueryCpusEntry, ncpus); for (i = 0; i < ncpus; i++) { virJSONValuePtr entry = virJSONValueArrayGet(data, i); @@ -2438,8 +2435,7 @@ qemuMonitorJSONBlockInfoAdd(virHashTablePtr table, struct qemuDomainDiskInfo *tmp = NULL; int ret = -1; - if (VIR_ALLOC(tmp) < 0) - goto cleanup; + tmp = g_new0(struct qemuDomainDiskInfo, 1); *tmp = *info; tmp->nodename = NULL; @@ -2555,8 +2551,7 @@ qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr dev, return NULL; } - if (VIR_ALLOC(bstats) < 0) - return NULL; + bstats = g_new0(qemuBlockStats, 1); #define QEMU_MONITOR_BLOCK_STAT_GET(NAME, VAR, MANDATORY) \ if (MANDATORY || virJSONValueObjectHasKey(stats, NAME)) { \ @@ -2595,8 +2590,7 @@ qemuMonitorJSONAddOneBlockStatsInfo(qemuBlockStatsPtr bstats, { qemuBlockStatsPtr copy = NULL; - if (VIR_ALLOC(copy) < 0) - return -1; + copy = g_new0(qemuBlockStats, 1); if (bstats) *copy = *bstats; @@ -2744,8 +2738,7 @@ qemuMonitorJSONBlockStatsUpdateCapacityData(virJSONValuePtr image, qemuBlockStatsPtr bstats; if (!(bstats = virHashLookup(stats, name))) { - if (VIR_ALLOC(bstats) < 0) - return -1; + bstats = g_new0(qemuBlockStats, 1); if (virHashAddEntry(stats, name, bstats) < 0) { VIR_FREE(bstats); @@ -4104,8 +4097,7 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValuePtr msg, goto cleanup; } nTable = virJSONValueArraySize(table); - if (VIR_ALLOC_N(fil->unicast.table, nTable)) - goto cleanup; + fil->unicast.table = g_new0(virMacAddr, nTable); for (i = 0; i < nTable; i++) { if (!(element = virJSONValueArrayGet(table, i)) || !(tmp = virJSONValueGetString(element))) { @@ -4146,8 +4138,7 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValuePtr msg, goto cleanup; } nTable = virJSONValueArraySize(table); - if (VIR_ALLOC_N(fil->multicast.table, nTable)) - goto cleanup; + fil->multicast.table = g_new0(virMacAddr, nTable); for (i = 0; i < nTable; i++) { if (!(element = virJSONValueArrayGet(table, i)) || !(tmp = virJSONValueGetString(element))) { @@ -4181,8 +4172,7 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValuePtr msg, goto cleanup; } nTable = virJSONValueArraySize(table); - if (VIR_ALLOC_N(fil->vlan.table, nTable)) - goto cleanup; + fil->vlan.table = g_new0(unsigned int, nTable); for (i = 0; i < nTable; i++) { if (!(element = virJSONValueArrayGet(table, i)) || virJSONValueGetNumberUint(element, &fil->vlan.table[i]) < 0) { @@ -4284,8 +4274,7 @@ qemuMonitorJSONExtractChardevInfo(virJSONValuePtr reply, goto cleanup; } - if (VIR_ALLOC(entry) < 0) - goto cleanup; + entry = g_new0(qemuMonitorChardevInfo, 1); if (STRPREFIX(type, "pty:")) entry->ptyPath = g_strdup(type + strlen("pty:")); @@ -4890,8 +4879,7 @@ qemuMonitorJSONParseBlockJobInfo(virHashTablePtr blockJobs, if (!rawjobname) device = qemuAliasDiskDriveSkipPrefix(device); - if (VIR_ALLOC(info) < 0) - return -1; + info = g_new0(qemuMonitorBlockJobInfo, 1); if (virHashAddEntry(blockJobs, device, info) < 0) { VIR_FREE(info); @@ -5576,16 +5564,14 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon, n = virJSONValueArraySize(data); /* null-terminated list */ - if (VIR_ALLOC_N(infolist, n + 1) < 0) - goto cleanup; + infolist = g_new0(qemuMonitorMachineInfoPtr, n + 1); for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); const char *tmp; qemuMonitorMachineInfoPtr info; - if (VIR_ALLOC(info) < 0) - goto cleanup; + info = g_new0(qemuMonitorMachineInfo, 1); infolist[i] = info; @@ -5745,8 +5731,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon, } cpu->usable = VIR_DOMCAPS_CPU_USABLE_NO; - if (VIR_ALLOC_N(cpu->blockers, len + 1) < 0) - return -1; + cpu->blockers = g_new0(char *, len + 1); for (j = 0; j < len; j++) { virJSONValuePtr blocker = virJSONValueArrayGet(blockers, j); @@ -5899,16 +5884,13 @@ qemuMonitorJSONParseCPUModel(const char *cpu_name, qemuMonitorCPUModelInfoPtr machine_model = NULL; int ret = -1; - if (VIR_ALLOC(machine_model) < 0) - goto cleanup; - + machine_model = g_new0(qemuMonitorCPUModelInfo, 1); machine_model->name = g_strdup(cpu_name); if (cpu_props) { size_t nprops = virJSONValueObjectKeysNumber(cpu_props); - if (VIR_ALLOC_N(machine_model->props, nprops) < 0) - goto cleanup; + machine_model->props = g_new0(qemuMonitorCPUProperty, nprops); if (virJSONValueObjectForeachKeyValue(cpu_props, qemuMonitorJSONParseCPUModelProperty, @@ -6113,8 +6095,7 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, n = virJSONValueArraySize(data); /* null-terminated list */ - if (VIR_ALLOC_N(commandlist, n + 1) < 0) - goto cleanup; + commandlist = g_new0(char *, n + 1); for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -6173,8 +6154,7 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon, n = virJSONValueArraySize(data); /* null-terminated list */ - if (VIR_ALLOC_N(eventlist, n + 1) < 0) - goto cleanup; + eventlist = g_new0(char *, n + 1); for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -6288,8 +6268,7 @@ qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon, n = virJSONValueArraySize(data); /* null-terminated list */ - if (VIR_ALLOC_N(paramlist, n + 1) < 0) - goto cleanup; + paramlist = g_new0(char *, n + 1); for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -6392,8 +6371,7 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon, n = virJSONValueArraySize(data); /* null-terminated list */ - if (VIR_ALLOC_N(typelist, n + 1) < 0) - goto cleanup; + typelist = g_new0(char *, n + 1); for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -6449,16 +6427,14 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitorPtr mon, n = virJSONValueArraySize(data); /* null-terminated list */ - if (VIR_ALLOC_N(pathlist, n + 1) < 0) - goto cleanup; + pathlist = g_new0(qemuMonitorJSONListPathPtr, n + 1); for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); const char *tmp; qemuMonitorJSONListPathPtr info; - if (VIR_ALLOC(info) < 0) - goto cleanup; + info = g_new0(qemuMonitorJSONListPath, 1); pathlist[i] = info; @@ -6612,8 +6588,7 @@ qemuMonitorJSONGetStringListProperty(qemuMonitorPtr mon, data = virJSONValueObjectGetArray(reply, "return"); n = virJSONValueArraySize(data); - if (VIR_ALLOC_N(list, n + 1) < 0) - return -1; + list = g_new0(char *, n + 1); for (i = 0; i < n; i++) { virJSONValuePtr item = virJSONValueArrayGet(data, i); @@ -6718,8 +6693,7 @@ qemuMonitorJSONParsePropsList(virJSONValuePtr cmd, n = virJSONValueArraySize(data); /* null-terminated list */ - if (VIR_ALLOC_N(proplist, n + 1) < 0) - goto cleanup; + proplist = g_new0(char *, n + 1); for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -6900,8 +6874,7 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon, caps = virJSONValueObjectGetArray(reply, "return"); n = virJSONValueArraySize(caps); - if (VIR_ALLOC_N(list, n + 1) < 0) - goto cleanup; + list = g_new0(char *, n + 1); for (i = 0; i < n; i++) { virJSONValuePtr cap = virJSONValueArrayGet(caps, i); @@ -7019,8 +6992,7 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon, goto cleanup; } - if (VIR_ALLOC_N(list, n) < 0) - goto cleanup; + list = g_new0(virGICCapability, n); for (i = 0; i < n; i++) { virJSONValuePtr cap = virJSONValueArrayGet(caps, i); @@ -7149,8 +7121,7 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon, goto cleanup; } - if (VIR_ALLOC(capability) < 0) - goto cleanup; + capability = g_new0(virSEVCapability, 1); capability->pdh = g_strdup(pdh); @@ -7345,8 +7316,7 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd, n = virJSONValueArraySize(data); /* null-terminated list */ - if (VIR_ALLOC_N(list, n + 1) < 0) - goto cleanup; + list = g_new0(char *, n + 1); for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -7641,8 +7611,7 @@ qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon, if (n < 0) return -1; - if (VIR_ALLOC_N(*aliases, n + 1) < 0) - goto cleanup; + *aliases = g_new0(char *, n + 1); alias = *aliases; for (i = 0; i < n; i++) { @@ -7655,7 +7624,6 @@ qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon, ret = 0; - cleanup: for (i = 0; i < n; i++) qemuMonitorJSONListPathFree(paths[i]); VIR_FREE(paths); @@ -8066,8 +8034,7 @@ qemuMonitorJSONGetIOThreads(qemuMonitorPtr mon, n = virJSONValueArraySize(data); /* null-terminated list */ - if (VIR_ALLOC_N(infolist, n + 1) < 0) - goto cleanup; + infolist = g_new0(qemuMonitorIOThreadInfoPtr, n + 1); for (i = 0; i < n; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); @@ -8083,8 +8050,7 @@ qemuMonitorJSONGetIOThreads(qemuMonitorPtr mon, if (!STRPREFIX(tmp, "iothread")) continue; - if (VIR_ALLOC(info) < 0) - goto cleanup; + info = g_new0(qemuMonitorIOThreadInfo, 1); infolist[i] = info; @@ -8225,8 +8191,7 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon, goto cleanup; } - if (VIR_ALLOC(meminfo) < 0) - goto cleanup; + meminfo = g_new0(qemuMonitorMemoryDeviceInfo, 1); if (virJSONValueObjectGetNumberUlong(dimminfo, "addr", &meminfo->address) < 0) { @@ -8672,8 +8637,7 @@ qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon, data = virJSONValueObjectGet(reply, "return"); ninfo = virJSONValueArraySize(data); - if (VIR_ALLOC_N(info, ninfo) < 0) - goto cleanup; + info = g_new0(struct qemuMonitorQueryHotpluggableCpusEntry, ninfo); for (i = 0; i < ninfo; i++) { vcpu = virJSONValueArrayGet(data, i); @@ -9073,8 +9037,7 @@ qemuMonitorJSONExtractPRManagerInfo(virJSONValuePtr reply, if (!(alias = virJSONValueObjectGetString(prManager, "id"))) goto malformed; - if (VIR_ALLOC(entry) < 0) - goto cleanup; + entry = g_new0(qemuMonitorPRManagerInfo, 1); if (virJSONValueObjectGetBoolean(prManager, "connected", @@ -9345,8 +9308,7 @@ qemuMonitorJSONGetJobInfoOne(virJSONValuePtr data) int tmp; g_autoptr(qemuMonitorJobInfo) job = NULL; - if (VIR_ALLOC(job) < 0) - return NULL; + job = g_new0(qemuMonitorJobInfo, 1); if ((tmp = qemuMonitorJobTypeFromString(type)) < 0) tmp = QEMU_MONITOR_JOB_TYPE_UNKNOWN; -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_process.c | 56 +++++++++++++---------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 93cbb37986..94b44f1c5c 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -302,8 +302,7 @@ qemuProcessHandleMonitorEOF(qemuMonitorPtr mon, goto cleanup; } - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_MONITOR_EOF; processEvent->vm = virObjectRef(vm); @@ -832,8 +831,7 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon G_GNUC_UNUSED, if (vm->def->watchdog->action == VIR_DOMAIN_WATCHDOG_ACTION_DUMP) { struct qemuProcessEvent *processEvent; - if (VIR_ALLOC(processEvent) < 0) - ; + processEvent = g_new0(qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_WATCHDOG; processEvent->action = VIR_DOMAIN_WATCHDOG_ACTION_DUMP; @@ -965,8 +963,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon G_GNUC_UNUSED, virDomainObjBroadcast(vm); } else { /* there is no waiting SYNC API, dispatch the update to a thread */ - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_BLOCK_JOB; data = g_strdup(diskAlias); @@ -1030,8 +1027,7 @@ qemuProcessHandleJobStatusChange(qemuMonitorPtr mon G_GNUC_UNUSED, virDomainObjBroadcast(vm); } else { VIR_DEBUG("job '%s' handled by event thread", jobname); - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE; processEvent->vm = virObjectRef(vm); @@ -1074,20 +1070,17 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon G_GNUC_UNUSED, virDomainEventGraphicsSubjectPtr subject = NULL; size_t i; - if (VIR_ALLOC(localAddr) < 0) - goto error; + localAddr = g_new0(virDomainEventGraphicsAddress, 1); localAddr->family = localFamily; localAddr->service = g_strdup(localService); localAddr->node = g_strdup(localNode); - if (VIR_ALLOC(remoteAddr) < 0) - goto error; + remoteAddr = g_new0(virDomainEventGraphicsAddress, 1); remoteAddr->family = remoteFamily; remoteAddr->service = g_strdup(remoteService); remoteAddr->node = g_strdup(remoteNode); - if (VIR_ALLOC(subject) < 0) - goto error; + subject = g_new0(virDomainEventGraphicsSubject, 1); if (x509dname) { if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) goto error; @@ -1329,8 +1322,7 @@ qemuProcessHandleGuestPanic(qemuMonitorPtr mon G_GNUC_UNUSED, struct qemuProcessEvent *processEvent; virObjectLock(vm); - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_GUESTPANIC; processEvent->action = vm->def->onCrash; @@ -1345,7 +1337,6 @@ qemuProcessHandleGuestPanic(qemuMonitorPtr mon G_GNUC_UNUSED, qemuProcessEventFree(processEvent); } - cleanup: virObjectUnlock(vm); return 0; @@ -1371,8 +1362,7 @@ qemuProcessHandleDeviceDeleted(qemuMonitorPtr mon G_GNUC_UNUSED, QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_OK)) goto cleanup; - if (VIR_ALLOC(processEvent) < 0) - goto error; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_DEVICE_DELETED; data = g_strdup(devAlias); @@ -1552,8 +1542,7 @@ qemuProcessHandleNicRxFilterChanged(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DEBUG("Device %s RX Filter changed in domain %p %s", devAlias, vm, vm->def->name); - if (VIR_ALLOC(processEvent) < 0) - goto error; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED; data = g_strdup(devAlias); @@ -1590,8 +1579,7 @@ qemuProcessHandleSerialChanged(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DEBUG("Serial port %s state changed to '%d' in domain %p %s", devAlias, connected, vm, vm->def->name); - if (VIR_ALLOC(processEvent) < 0) - goto error; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_SERIAL_CHANGED; data = g_strdup(devAlias); @@ -1800,8 +1788,7 @@ qemuProcessHandlePRManagerStatusChanged(qemuMonitorPtr mon G_GNUC_UNUSED, priv = vm->privateData; priv->prDaemonRunning = false; - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_PR_DISCONNECT; processEvent->vm = virObjectRef(vm); @@ -1838,8 +1825,7 @@ qemuProcessHandleRdmaGidStatusChanged(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DEBUG("netdev=%s,gid_status=%d,subnet_prefix=0x%llx,interface_id=0x%llx", netdev, gid_status, subnet_prefix, interface_id); - if (VIR_ALLOC(info) < 0) - goto cleanup; + info = g_new0(qemuMonitorRdmaGidStatus, 1); info->netdev = g_strdup(netdev); @@ -1847,8 +1833,7 @@ qemuProcessHandleRdmaGidStatusChanged(qemuMonitorPtr mon G_GNUC_UNUSED, info->subnet_prefix = subnet_prefix; info->interface_id = interface_id; - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED; processEvent->vm = virObjectRef(vm); @@ -1877,8 +1862,7 @@ qemuProcessHandleGuestCrashloaded(qemuMonitorPtr mon G_GNUC_UNUSED, struct qemuProcessEvent *processEvent; virObjectLock(vm); - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_GUEST_CRASHLOADED; processEvent->vm = virObjectRef(vm); @@ -1888,7 +1872,6 @@ qemuProcessHandleGuestCrashloaded(qemuMonitorPtr mon G_GNUC_UNUSED, qemuProcessEventFree(processEvent); } - cleanup: virObjectUnlock(vm); return 0; @@ -4589,8 +4572,7 @@ qemuProcessIncomingDefNew(virQEMUCapsPtr qemuCaps, if (qemuMigrationDstCheckProtocol(qemuCaps, migrateFrom) < 0) return NULL; - if (VIR_ALLOC(inc) < 0) - return NULL; + inc = g_new0(qemuProcessIncomingDef, 1); inc->address = g_strdup(listenAddress); @@ -8431,8 +8413,7 @@ qemuProcessReconnectHelper(virDomainObjPtr obj, if (!obj->pid) return 0; - if (VIR_ALLOC(data) < 0) - return -1; + data = g_new0(struct qemuProcessReconnectData, 1); memcpy(data, src, sizeof(*data)); data->obj = obj; @@ -8588,8 +8569,7 @@ qemuProcessQMPNew(const char *binary, VIR_DEBUG("exec=%s, libDir=%s, runUid=%u, runGid=%u, forceTCG=%d", binary, libDir, runUid, runGid, forceTCG); - if (VIR_ALLOC(proc) < 0) - return NULL; + proc = g_new0(qemuProcessQMP, 1); proc->binary = g_strdup(binary); proc->libDir = g_strdup(libDir); -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- Oops, forgot to squash some changes in. src/qemu/qemu_process.c | 56 +++++++++++++---------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 93cbb37986..cb378a86aa 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -302,8 +302,7 @@ qemuProcessHandleMonitorEOF(qemuMonitorPtr mon, goto cleanup; } - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_MONITOR_EOF; processEvent->vm = virObjectRef(vm); @@ -832,8 +831,7 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon G_GNUC_UNUSED, if (vm->def->watchdog->action == VIR_DOMAIN_WATCHDOG_ACTION_DUMP) { struct qemuProcessEvent *processEvent; - if (VIR_ALLOC(processEvent) < 0) - ; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_WATCHDOG; processEvent->action = VIR_DOMAIN_WATCHDOG_ACTION_DUMP; @@ -965,8 +963,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon G_GNUC_UNUSED, virDomainObjBroadcast(vm); } else { /* there is no waiting SYNC API, dispatch the update to a thread */ - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_BLOCK_JOB; data = g_strdup(diskAlias); @@ -1030,8 +1027,7 @@ qemuProcessHandleJobStatusChange(qemuMonitorPtr mon G_GNUC_UNUSED, virDomainObjBroadcast(vm); } else { VIR_DEBUG("job '%s' handled by event thread", jobname); - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE; processEvent->vm = virObjectRef(vm); @@ -1074,20 +1070,17 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon G_GNUC_UNUSED, virDomainEventGraphicsSubjectPtr subject = NULL; size_t i; - if (VIR_ALLOC(localAddr) < 0) - goto error; + localAddr = g_new0(virDomainEventGraphicsAddress, 1); localAddr->family = localFamily; localAddr->service = g_strdup(localService); localAddr->node = g_strdup(localNode); - if (VIR_ALLOC(remoteAddr) < 0) - goto error; + remoteAddr = g_new0(virDomainEventGraphicsAddress, 1); remoteAddr->family = remoteFamily; remoteAddr->service = g_strdup(remoteService); remoteAddr->node = g_strdup(remoteNode); - if (VIR_ALLOC(subject) < 0) - goto error; + subject = g_new0(virDomainEventGraphicsSubject, 1); if (x509dname) { if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) goto error; @@ -1329,8 +1322,7 @@ qemuProcessHandleGuestPanic(qemuMonitorPtr mon G_GNUC_UNUSED, struct qemuProcessEvent *processEvent; virObjectLock(vm); - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_GUESTPANIC; processEvent->action = vm->def->onCrash; @@ -1345,7 +1337,6 @@ qemuProcessHandleGuestPanic(qemuMonitorPtr mon G_GNUC_UNUSED, qemuProcessEventFree(processEvent); } - cleanup: virObjectUnlock(vm); return 0; @@ -1371,8 +1362,7 @@ qemuProcessHandleDeviceDeleted(qemuMonitorPtr mon G_GNUC_UNUSED, QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_OK)) goto cleanup; - if (VIR_ALLOC(processEvent) < 0) - goto error; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_DEVICE_DELETED; data = g_strdup(devAlias); @@ -1552,8 +1542,7 @@ qemuProcessHandleNicRxFilterChanged(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DEBUG("Device %s RX Filter changed in domain %p %s", devAlias, vm, vm->def->name); - if (VIR_ALLOC(processEvent) < 0) - goto error; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED; data = g_strdup(devAlias); @@ -1590,8 +1579,7 @@ qemuProcessHandleSerialChanged(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DEBUG("Serial port %s state changed to '%d' in domain %p %s", devAlias, connected, vm, vm->def->name); - if (VIR_ALLOC(processEvent) < 0) - goto error; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_SERIAL_CHANGED; data = g_strdup(devAlias); @@ -1800,8 +1788,7 @@ qemuProcessHandlePRManagerStatusChanged(qemuMonitorPtr mon G_GNUC_UNUSED, priv = vm->privateData; priv->prDaemonRunning = false; - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_PR_DISCONNECT; processEvent->vm = virObjectRef(vm); @@ -1838,8 +1825,7 @@ qemuProcessHandleRdmaGidStatusChanged(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DEBUG("netdev=%s,gid_status=%d,subnet_prefix=0x%llx,interface_id=0x%llx", netdev, gid_status, subnet_prefix, interface_id); - if (VIR_ALLOC(info) < 0) - goto cleanup; + info = g_new0(qemuMonitorRdmaGidStatus, 1); info->netdev = g_strdup(netdev); @@ -1847,8 +1833,7 @@ qemuProcessHandleRdmaGidStatusChanged(qemuMonitorPtr mon G_GNUC_UNUSED, info->subnet_prefix = subnet_prefix; info->interface_id = interface_id; - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED; processEvent->vm = virObjectRef(vm); @@ -1877,8 +1862,7 @@ qemuProcessHandleGuestCrashloaded(qemuMonitorPtr mon G_GNUC_UNUSED, struct qemuProcessEvent *processEvent; virObjectLock(vm); - if (VIR_ALLOC(processEvent) < 0) - goto cleanup; + processEvent = g_new0(struct qemuProcessEvent, 1); processEvent->eventType = QEMU_PROCESS_EVENT_GUEST_CRASHLOADED; processEvent->vm = virObjectRef(vm); @@ -1888,7 +1872,6 @@ qemuProcessHandleGuestCrashloaded(qemuMonitorPtr mon G_GNUC_UNUSED, qemuProcessEventFree(processEvent); } - cleanup: virObjectUnlock(vm); return 0; @@ -4589,8 +4572,7 @@ qemuProcessIncomingDefNew(virQEMUCapsPtr qemuCaps, if (qemuMigrationDstCheckProtocol(qemuCaps, migrateFrom) < 0) return NULL; - if (VIR_ALLOC(inc) < 0) - return NULL; + inc = g_new0(qemuProcessIncomingDef, 1); inc->address = g_strdup(listenAddress); @@ -8431,8 +8413,7 @@ qemuProcessReconnectHelper(virDomainObjPtr obj, if (!obj->pid) return 0; - if (VIR_ALLOC(data) < 0) - return -1; + data = g_new0(struct qemuProcessReconnectData, 1); memcpy(data, src, sizeof(*data)); data->obj = obj; @@ -8588,8 +8569,7 @@ qemuProcessQMPNew(const char *binary, VIR_DEBUG("exec=%s, libDir=%s, runUid=%u, runGid=%u, forceTCG=%d", binary, libDir, runUid, runGid, forceTCG); - if (VIR_ALLOC(proc) < 0) - return NULL; + proc = g_new0(qemuProcessQMP, 1); proc->binary = g_strdup(binary); proc->libDir = g_strdup(libDir); -- 2.26.2

[...] Coverity notes...
@@ -1074,20 +1070,17 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon G_GNUC_UNUSED, virDomainEventGraphicsSubjectPtr subject = NULL; size_t i;
- if (VIR_ALLOC(localAddr) < 0) - goto error; + localAddr = g_new0(virDomainEventGraphicsAddress, 1); localAddr->family = localFamily; localAddr->service = g_strdup(localService); localAddr->node = g_strdup(localNode);
- if (VIR_ALLOC(remoteAddr) < 0) - goto error; + remoteAddr = g_new0(virDomainEventGraphicsAddress, 1); remoteAddr->family = remoteFamily; remoteAddr->service = g_strdup(remoteService); remoteAddr->node = g_strdup(remoteNode);
- if (VIR_ALLOC(subject) < 0) - goto error; + subject = g_new0(virDomainEventGraphicsSubject, 1); if (x509dname) { if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) goto error;
There's no way to error: now w/o @localAddr, @remoteAddr, & @subject being allocated, thus there's no need to check whether they're non-null before accessing. John [...]

On a Tuesday in 2020, John Ferlan wrote:
[...]
Coverity notes...
@@ -1074,20 +1070,17 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon G_GNUC_UNUSED, virDomainEventGraphicsSubjectPtr subject = NULL; size_t i;
- if (VIR_ALLOC(localAddr) < 0) - goto error; + localAddr = g_new0(virDomainEventGraphicsAddress, 1); localAddr->family = localFamily; localAddr->service = g_strdup(localService); localAddr->node = g_strdup(localNode);
- if (VIR_ALLOC(remoteAddr) < 0) - goto error; + remoteAddr = g_new0(virDomainEventGraphicsAddress, 1); remoteAddr->family = remoteFamily; remoteAddr->service = g_strdup(remoteService); remoteAddr->node = g_strdup(remoteNode);
- if (VIR_ALLOC(subject) < 0) - goto error; + subject = g_new0(virDomainEventGraphicsSubject, 1); if (x509dname) { if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) goto error;
There's no way to error: now w/o @localAddr, @remoteAddr, & @subject being allocated, thus there's no need to check whether they're non-null before accessing.
Actually, there's no way to error at all - VIR_REALLOC_N aborts on OOM. I don't think it's worth deleting in the meantime. Jano
John
[...]

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_command.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index e9ba81d82f..476cf6972e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7428,8 +7428,7 @@ qemuBuildNumaCommandLine(virQEMUDriverConfigPtr cfg, hmat = true; } - if (VIR_ALLOC_N(nodeBackends, ncells) < 0) - goto cleanup; + nodeBackends = g_new0(virBuffer, ncells); /* using of -numa memdev= cannot be combined with -numa mem=, thus we * need to check which approach to use */ @@ -8119,9 +8118,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, if (!tapfdSize) tapfdSize = 1; - if (VIR_ALLOC_N(tapfd, tapfdSize) < 0 || - VIR_ALLOC_N(tapfdName, tapfdSize) < 0) - goto cleanup; + tapfd = g_new0(int, tapfdSize); + tapfdName = g_new0(char *, tapfdSize); memset(tapfd, -1, tapfdSize * sizeof(tapfd[0])); @@ -8135,9 +8133,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, if (!tapfdSize) tapfdSize = 1; - if (VIR_ALLOC_N(tapfd, tapfdSize) < 0 || - VIR_ALLOC_N(tapfdName, tapfdSize) < 0) - goto cleanup; + tapfd = g_new0(int, tapfdSize); + tapfdName = g_new0(char *, tapfdSize); memset(tapfd, -1, tapfdSize * sizeof(tapfd[0])); @@ -8151,9 +8148,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, if (!tapfdSize) tapfdSize = 1; - if (VIR_ALLOC_N(tapfd, tapfdSize) < 0 || - VIR_ALLOC_N(tapfdName, tapfdSize) < 0) - goto cleanup; + tapfd = g_new0(int, tapfdSize); + tapfdName = g_new0(char *, tapfdSize); memset(tapfd, -1, tapfdSize * sizeof(tapfd[0])); @@ -8268,9 +8264,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, if (!vhostfdSize) vhostfdSize = 1; - if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0 || - VIR_ALLOC_N(vhostfdName, vhostfdSize)) - goto cleanup; + vhostfd = g_new0(int, vhostfdSize); + vhostfdName = g_new0(char *, vhostfdSize); memset(vhostfd, -1, vhostfdSize * sizeof(vhostfd[0])); @@ -10465,8 +10460,7 @@ qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk, { g_autoptr(qemuBlockStorageSourceAttachData) data = NULL; - if (VIR_ALLOC(data) < 0) - return NULL; + data = g_new0(qemuBlockStorageSourceAttachData, 1); if (!(data->driveCmd = qemuBuildDriveStr(disk, qemuCaps)) || !(data->driveAlias = qemuAliasDiskDriveFromDisk(disk))) @@ -10543,8 +10537,7 @@ qemuBuildStorageSourceChainAttachPrepareDrive(virDomainDiskDefPtr disk, g_autoptr(qemuBlockStorageSourceAttachData) elem = NULL; g_autoptr(qemuBlockStorageSourceChainData) data = NULL; - if (VIR_ALLOC(data) < 0) - return NULL; + data = g_new0(qemuBlockStorageSourceChainData, 1); if (!(elem = qemuBuildStorageSourceAttachPrepareDrive(disk, qemuCaps))) return NULL; @@ -10595,8 +10588,7 @@ qemuBuildStorageSourceChainAttachPrepareBlockdev(virStorageSourcePtr top, g_autoptr(qemuBlockStorageSourceChainData) data = NULL; virStorageSourcePtr n; - if (VIR_ALLOC(data) < 0) - return NULL; + data = g_new0(qemuBlockStorageSourceChainData, 1); for (n = top; virStorageSourceIsBacking(n); n = n->backingStore) { if (qemuBuildStorageSourceChainAttachPrepareBlockdevOne(data, n, @@ -10625,8 +10617,7 @@ qemuBuildStorageSourceChainAttachPrepareBlockdevTop(virStorageSourcePtr top, { g_autoptr(qemuBlockStorageSourceChainData) data = NULL; - if (VIR_ALLOC(data) < 0) - return NULL; + data = g_new0(qemuBlockStorageSourceChainData, 1); if (qemuBuildStorageSourceChainAttachPrepareBlockdevOne(data, top, backingStore, qemuCaps) < 0) -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_firmware.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index 480ce0b00d..eebe6fcf78 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -301,8 +301,7 @@ qemuFirmwareInterfaceParse(const char *path, ninterfaces = virJSONValueArraySize(interfacesJSON); - if (VIR_ALLOC_N(interfaces, ninterfaces) < 0) - return -1; + interfaces = g_new0(qemuFirmwareOSInterface, ninterfaces); for (i = 0; i < ninterfaces; i++) { virJSONValuePtr item = virJSONValueArrayGet(interfacesJSON, i); @@ -504,8 +503,7 @@ qemuFirmwareTargetParse(const char *path, ntargets = virJSONValueArraySize(targetsJSON); - if (VIR_ALLOC_N(targets, ntargets) < 0) - return -1; + targets = g_new0(qemuFirmwareTargetPtr, ntargets); for (i = 0; i < ntargets; i++) { virJSONValuePtr item = virJSONValueArrayGet(targetsJSON, i); @@ -515,8 +513,7 @@ qemuFirmwareTargetParse(const char *path, size_t nmachines; size_t j; - if (VIR_ALLOC(t) < 0) - goto cleanup; + t = g_new0(qemuFirmwareTarget, 1); if (!(architectureStr = virJSONValueObjectGetString(item, "architecture"))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -541,8 +538,7 @@ qemuFirmwareTargetParse(const char *path, nmachines = virJSONValueArraySize(machines); - if (VIR_ALLOC_N(t->machines, nmachines) < 0) - goto cleanup; + t->machines = g_new0(char *, nmachines); for (j = 0; j < nmachines; j++) { virJSONValuePtr machine = virJSONValueArrayGet(machines, j); @@ -588,8 +584,7 @@ qemuFirmwareFeatureParse(const char *path, nfeatures = virJSONValueArraySize(featuresJSON); - if (VIR_ALLOC_N(features, nfeatures) < 0) - return -1; + features = g_new0(qemuFirmwareFeature, nfeatures); for (i = 0; i < nfeatures; i++) { virJSONValuePtr item = virJSONValueArrayGet(featuresJSON, i); @@ -632,8 +627,7 @@ qemuFirmwareParse(const char *path) return NULL; } - if (VIR_ALLOC(fw) < 0) - return NULL; + fw = g_new0(qemuFirmware, 1); if (qemuFirmwareInterfaceParse(path, doc, fw) < 0) return NULL; @@ -1050,9 +1044,8 @@ qemuFirmwareEnableFeatures(virQEMUDriverPtr driver, switch (fw->mapping.device) { case QEMU_FIRMWARE_DEVICE_FLASH: - if (!def->os.loader && - VIR_ALLOC(def->os.loader) < 0) - return -1; + if (!def->os.loader) + def->os.loader = g_new0(virDomainLoaderDef, 1); def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_PFLASH; def->os.loader->readonly = VIR_TRISTATE_BOOL_YES; @@ -1093,9 +1086,8 @@ qemuFirmwareEnableFeatures(virQEMUDriverPtr driver, break; case QEMU_FIRMWARE_DEVICE_MEMORY: - if (!def->os.loader && - VIR_ALLOC(def->os.loader) < 0) - return -1; + if (!def->os.loader) + def->os.loader = g_new0(virDomainLoaderDef, 1); def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_ROM; def->os.loader->path = g_strdup(memory->filename); @@ -1201,8 +1193,7 @@ qemuFirmwareFetchParsedConfigs(bool privileged, npaths = virStringListLength((const char **)paths); - if (VIR_ALLOC_N(firmwares, npaths) < 0) - return -1; + firmwares = g_new0(qemuFirmwarePtr, npaths); for (i = 0; i < npaths; i++) { if (!(firmwares[i] = qemuFirmwareParse(paths[i]))) @@ -1431,8 +1422,7 @@ qemuFirmwareGetSupported(const char *machine, } if (j == *nfws) { - if (VIR_ALLOC(tmp) < 0) - return -1; + tmp = g_new0(virFirmware, 1); tmp->name = g_strdup(fwpath); tmp->nvram = g_strdup(nvrampath); -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_agent.c | 6 ++---- src/qemu/qemu_block.c | 15 +++++---------- src/qemu/qemu_cgroup.c | 6 ++---- src/qemu/qemu_conf.c | 20 ++++++++------------ src/qemu/qemu_domain_address.c | 3 +-- src/qemu/qemu_hotplug.c | 29 +++++++++++------------------ src/qemu/qemu_migration.c | 6 ++---- src/qemu/qemu_monitor.c | 13 +++---------- src/qemu/qemu_namespace.c | 3 +-- src/qemu/qemu_saveimage.c | 3 +-- src/qemu/qemu_vhost_user.c | 17 +++++++---------- 11 files changed, 43 insertions(+), 78 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 1239aceb46..09116e749c 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1452,8 +1452,7 @@ qemuAgentGetVCPUs(qemuAgentPtr agent, ndata = virJSONValueArraySize(data); - if (VIR_ALLOC_N(*info, ndata) < 0) - goto cleanup; + *info = g_new0(qemuAgentCPUInfo, ndata); for (i = 0; i < ndata; i++) { virJSONValuePtr entry = virJSONValueArrayGet(data, i); @@ -2148,8 +2147,7 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, if (VIR_EXPAND_N(ifaces_ret, ifaces_count, 1) < 0) goto error; - if (VIR_ALLOC(ifaces_ret[ifaces_count - 1]) < 0) - goto error; + ifaces_ret[ifaces_count - 1] = g_new0(virDomainInterface, 1); if (virHashAddEntry(ifaces_store, ifname_s, ifaces_ret[ifaces_count - 1]) < 0) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 487b0a72e7..6bea21347a 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -169,8 +169,7 @@ qemuBlockNodeNameGetBackingChainBacking(virJSONValuePtr next, } } - if (VIR_ALLOC(data) < 0) - return -1; + data = g_new0(qemuBlockNodeNameBackingChainData, 1); data->nodeformat = g_strdup(nodename); data->nodestorage = g_strdup(parentnodename); @@ -415,8 +414,7 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src) return NULL; } - if (VIR_ALLOC(uri) < 0) - return NULL; + uri = g_new0(virURI, 1); if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) { uri->port = src->hosts->port; @@ -1595,8 +1593,7 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src, if (autoreadonly) backendpropsflags |= QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_AUTO_READONLY; - if (VIR_ALLOC(data) < 0) - return NULL; + data = g_new0(qemuBlockStorageSourceAttachData, 1); if (!(data->formatProps = qemuBlockStorageSourceGetBlockdevProps(src, backingStore)) || @@ -1886,8 +1883,7 @@ qemuBlockStorageSourceChainDetachPrepareBlockdev(virStorageSourcePtr src) g_autoptr(qemuBlockStorageSourceChainData) data = NULL; virStorageSourcePtr n; - if (VIR_ALLOC(data) < 0) - return NULL; + data = g_new0(qemuBlockStorageSourceChainData, 1); for (n = src; virStorageSourceIsBacking(n); n = n->backingStore) { if (!(backend = qemuBlockStorageSourceDetachPrepare(n, NULL))) @@ -1916,8 +1912,7 @@ qemuBlockStorageSourceChainDetachPrepareDrive(virStorageSourcePtr src, g_autoptr(qemuBlockStorageSourceAttachData) backend = NULL; g_autoptr(qemuBlockStorageSourceChainData) data = NULL; - if (VIR_ALLOC(data) < 0) - return NULL; + data = g_new0(qemuBlockStorageSourceChainData, 1); if (!(backend = qemuBlockStorageSourceDetachPrepare(src, driveAlias))) return NULL; diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index e88da02341..b671991ad6 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -926,8 +926,7 @@ qemuInitCgroup(virDomainObjPtr vm, if (!vm->def->resource) { virDomainResourceDefPtr res; - if (VIR_ALLOC(res) < 0) - return -1; + res = g_new0(virDomainResourceDef, 1); res->partition = g_strdup("/machine"); @@ -1252,8 +1251,7 @@ qemuCgroupEmulatorAllNodesAllow(virCgroupPtr cgroup, if (!(all_nodes_str = virBitmapFormat(all_nodes))) goto cleanup; - if (VIR_ALLOC(data) < 0) - goto cleanup; + data = g_new0(qemuCgroupEmulatorAllNodesData, 1); if (virCgroupNewThread(cgroup, VIR_CGROUP_THREAD_EMULATOR, 0, false, &data->emulatorCgroup) < 0) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index f4ed1fa061..6d16c11017 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -641,9 +641,8 @@ virQEMUDriverConfigLoadProcessEntry(virQEMUDriverConfigPtr cfg, VIR_FREE(cfg->hugetlbfs); cfg->nhugetlbfs = virStringListLength((const char *const *)hugetlbfs); - if (hugetlbfs[0] && - VIR_ALLOC_N(cfg->hugetlbfs, cfg->nhugetlbfs) < 0) - return -1; + if (hugetlbfs[0]) + cfg->hugetlbfs = g_new0(virHugeTLBFS, cfg->nhugetlbfs); for (i = 0; hugetlbfs[i] != NULL; i++) { if (virQEMUDriverConfigHugeTLBFSInit(&cfg->hugetlbfs[i], @@ -840,12 +839,11 @@ virQEMUDriverConfigLoadNVRAMEntry(virQEMUDriverConfigPtr cfg, } cfg->nfirmwares = virStringListLength((const char *const *)nvram); - if (nvram[0] && VIR_ALLOC_N(cfg->firmwares, cfg->nfirmwares) < 0) - return -1; + if (nvram[0]) + cfg->firmwares = g_new0(virFirmwarePtr, cfg->nfirmwares); for (i = 0; nvram[i] != NULL; i++) { - if (VIR_ALLOC(cfg->firmwares[i]) < 0) - return -1; + cfg->firmwares[i] = g_new0(virFirmware, 1); if (virFirmwareParse(nvram[i], cfg->firmwares[i]) < 0) return -1; } @@ -1349,8 +1347,7 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) ; caps->host.nsecModels = i; - if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0) - return NULL; + caps->host.secModels = g_new0(virCapsHostSecModel, caps->host.nsecModels); for (i = 0; sec_managers[i]; i++) { virCapsHostSecModelPtr sm = &caps->host.secModels[i]; @@ -1616,9 +1613,8 @@ qemuSharedDeviceEntryInsert(virQEMUDriverPtr driver, entry->domains[entry->ref - 1] = g_strdup(name); } } else { - if (VIR_ALLOC(entry) < 0 || - VIR_ALLOC_N(entry->domains, 1) < 0) - goto error; + entry = g_new0(qemuSharedDeviceEntry, 1); + entry->domains = g_new0(char *, 1); entry->domains[0] = g_strdup(name); diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 61eb53ea2c..0199a620a0 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -3038,8 +3038,7 @@ qemuDomainUSBAddressAddHubs(virDomainDefPtr def) data.count, available_ports, hubs_needed); for (i = 0; i < hubs_needed; i++) { - if (VIR_ALLOC(hub) < 0) - return -1; + hub = g_new0(virDomainHubDef, 1); hub->type = VIR_DOMAIN_HUB_TYPE_USB; if (VIR_APPEND_ELEMENT(def->hubs, def->nhubs, hub) < 0) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 11b549b12b..09f8525cfa 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -928,8 +928,7 @@ qemuDomainFindOrCreateSCSIDiskController(virQEMUDriverPtr driver, /* No SCSI controller present, for backward compatibility we * now hotplug a controller */ - if (VIR_ALLOC(cont) < 0) - return NULL; + cont = g_new0(virDomainControllerDef, 1); cont->type = VIR_DOMAIN_CONTROLLER_TYPE_SCSI; cont->idx = controller; if (model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_DEFAULT) @@ -1243,11 +1242,9 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, if (!tapfdSize) tapfdSize = vhostfdSize = 1; queueSize = tapfdSize; - if (VIR_ALLOC_N(tapfd, tapfdSize) < 0) - goto cleanup; + tapfd = g_new0(int, tapfdSize); memset(tapfd, -1, sizeof(*tapfd) * tapfdSize); - if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) - goto cleanup; + vhostfd = g_new0(int, vhostfdSize); memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize); if (qemuInterfaceBridgeConnect(vm->def, driver, net, tapfd, &tapfdSize) < 0) @@ -1262,11 +1259,9 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, if (!tapfdSize) tapfdSize = vhostfdSize = 1; queueSize = tapfdSize; - if (VIR_ALLOC_N(tapfd, tapfdSize) < 0) - goto cleanup; + tapfd = g_new0(int, tapfdSize); memset(tapfd, -1, sizeof(*tapfd) * tapfdSize); - if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) - goto cleanup; + vhostfd = g_new0(int, vhostfdSize); memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize); if (qemuInterfaceDirectConnect(vm->def, driver, net, tapfd, tapfdSize, @@ -1282,10 +1277,9 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, if (!tapfdSize) tapfdSize = vhostfdSize = 1; queueSize = tapfdSize; - if (VIR_ALLOC_N(tapfd, tapfdSize) < 0) - goto cleanup; + tapfd = g_new0(int, tapfdSize); memset(tapfd, -1, sizeof(*tapfd) * tapfdSize); - if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) + vhostfd = g_new0(int, vhostfdSize); goto cleanup; memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize); if (qemuInterfaceEthernetConnect(vm->def, driver, net, @@ -1381,9 +1375,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, goto cleanup; } - if (VIR_ALLOC_N(tapfdName, tapfdSize) < 0 || - VIR_ALLOC_N(vhostfdName, vhostfdSize) < 0) - goto cleanup; + tapfdName = g_new0(char *, tapfdSize); + vhostfdName = g_new0(char *, vhostfdSize); for (i = 0; i < tapfdSize; i++) tapfdName[i] = g_strdup_printf("fd-%s%zu", net->info.alias, i); @@ -1973,8 +1966,8 @@ qemuDomainChrPreInsert(virDomainDefPtr vmdef, */ if (vmdef->nserials == 0 && vmdef->nconsoles == 0 && chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL) { - if (!vmdef->consoles && VIR_ALLOC(vmdef->consoles) < 0) - return -1; + if (!vmdef->consoles) + vmdef->consoles = g_new0(virDomainChrDefPtr, 1); /* We'll be dealing with serials[0] directly, so NULL is fine here. */ if (!(vmdef->consoles[0] = virDomainChrDefNew(NULL))) { diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 403f5d3e13..2000c86640 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3309,8 +3309,7 @@ static void qemuMigrationSrcIOFunc(void *arg) VIR_DEBUG("Running migration tunnel; stream=%p, sock=%d", data->st, data->sock); - if (VIR_ALLOC_N(buffer, TUNNEL_SEND_BUF_SIZE) < 0) - goto abrt; + buffer = g_new0(char, TUNNEL_SEND_BUF_SIZE); fds[0].fd = data->sock; fds[1].fd = data->wakeupRecvFD; @@ -3414,8 +3413,7 @@ qemuMigrationSrcStartTunnel(virStreamPtr st, if (virPipe(wakeupFD) < 0) goto error; - if (VIR_ALLOC(io) < 0) - goto error; + io = g_new0(qemuMigrationIOThread, 1); io->st = st; io->sock = sock; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index eb4b04dc1a..27ad739983 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1869,8 +1869,7 @@ qemuMonitorGetCPUInfo(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (VIR_ALLOC_N(info, maxvcpus) < 0) - return -1; + info = g_new0(qemuMonitorCPUInfo, maxvcpus); /* initialize a few non-zero defaults */ qemuMonitorCPUInfoClear(info, maxvcpus); @@ -3685,11 +3684,9 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig) qemuMonitorCPUModelInfoPtr copy; size_t i; - if (VIR_ALLOC(copy) < 0) - goto error; + copy = g_new0(qemuMonitorCPUModelInfo, 1); - if (VIR_ALLOC_N(copy->props, orig->nprops) < 0) - goto error; + copy->props = g_new0(qemuMonitorCPUProperty, orig->nprops); copy->name = g_strdup(orig->name); @@ -3720,10 +3717,6 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig) } return copy; - - error: - qemuMonitorCPUModelInfoFree(copy); - return NULL; } diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index b0d1d0d083..5c58893693 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -155,8 +155,7 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr cfg, } } - if (VIR_ALLOC_N(paths, nmounts) < 0) - goto error; + paths = g_new0(char *, nmounts); for (i = 0; i < nmounts; i++) { if (!(paths[i] = qemuDomainGetPreservedMountPath(cfg, vm, mounts[i]))) diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c index 52468056ad..0e588d463d 100644 --- a/src/qemu/qemu_saveimage.c +++ b/src/qemu/qemu_saveimage.c @@ -103,8 +103,7 @@ virQEMUSaveDataNew(char *domXML, virQEMUSaveDataPtr data = NULL; virQEMUSaveHeaderPtr header; - if (VIR_ALLOC(data) < 0) - return NULL; + data = g_new0(virQEMUSaveData, 1); data->xml = g_steal_pointer(&domXML); diff --git a/src/qemu/qemu_vhost_user.c b/src/qemu/qemu_vhost_user.c index be7c3dd5b8..260f3cd550 100644 --- a/src/qemu/qemu_vhost_user.c +++ b/src/qemu/qemu_vhost_user.c @@ -196,8 +196,7 @@ qemuVhostUserParse(const char *path) return NULL; } - if (VIR_ALLOC(vu) < 0) - return NULL; + vu = g_new0(qemuVhostUser, 1); if (qemuVhostUserTypeParse(path, doc, vu) < 0) return NULL; @@ -253,8 +252,7 @@ qemuVhostUserFetchParsedConfigs(bool privileged, npaths = virStringListLength((const char **)paths); - if (VIR_ALLOC_N(vus, npaths) < 0) - return -1; + vus = g_new0(qemuVhostUserPtr, npaths); for (i = 0; i < npaths; i++) { if (!(vus[i] = qemuVhostUserParse(paths[i]))) @@ -292,8 +290,7 @@ qemuVhostUserGPUFillCapabilities(qemuVhostUserPtr vu, } nfeatures = virJSONValueArraySize(featuresJSON); - if (VIR_ALLOC_N(features, nfeatures) < 0) - return -1; + features = g_new0(qemuVhostUserGPUFeature, nfeatures); for (i = 0; i < nfeatures; i++) { virJSONValuePtr item = virJSONValueArrayGet(featuresJSON, i); @@ -382,8 +379,8 @@ qemuVhostUserFillDomainGPU(virQEMUDriverPtr driver, continue; } - if (!video->driver && VIR_ALLOC(video->driver) < 0) - goto end; + if (!video->driver) + video->driver = g_new0(virDomainVideoDriverDef, 1); VIR_FREE(video->driver->vhost_user_binary); video->driver->vhost_user_binary = g_strdup(vu->binary); @@ -397,8 +394,8 @@ qemuVhostUserFillDomainGPU(virQEMUDriverPtr driver, goto end; } - if (!video->accel && VIR_ALLOC(video->accel) < 0) - goto end; + if (!video->accel) + video->accel = g_new0(virDomainVideoAccelDef, 1); if (!video->accel->rendernode && qemuVhostUserGPUHasFeature(&vu->capabilities.gpu, -- 2.26.2

Coverity notes ...
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 11b549b12b..09f8525cfa 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -928,8 +928,7 @@ qemuDomainFindOrCreateSCSIDiskController(virQEMUDriverPtr driver,
/* No SCSI controller present, for backward compatibility we * now hotplug a controller */ - if (VIR_ALLOC(cont) < 0) - return NULL; + cont = g_new0(virDomainControllerDef, 1); cont->type = VIR_DOMAIN_CONTROLLER_TYPE_SCSI; cont->idx = controller; if (model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_DEFAULT) @@ -1243,11 +1242,9 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, if (!tapfdSize) tapfdSize = vhostfdSize = 1; queueSize = tapfdSize; - if (VIR_ALLOC_N(tapfd, tapfdSize) < 0) - goto cleanup; + tapfd = g_new0(int, tapfdSize); memset(tapfd, -1, sizeof(*tapfd) * tapfdSize); - if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) - goto cleanup; + vhostfd = g_new0(int, vhostfdSize); memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize); if (qemuInterfaceBridgeConnect(vm->def, driver, net, tapfd, &tapfdSize) < 0) @@ -1262,11 +1259,9 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, if (!tapfdSize) tapfdSize = vhostfdSize = 1; queueSize = tapfdSize; - if (VIR_ALLOC_N(tapfd, tapfdSize) < 0) - goto cleanup; + tapfd = g_new0(int, tapfdSize); memset(tapfd, -1, sizeof(*tapfd) * tapfdSize); - if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) - goto cleanup; + vhostfd = g_new0(int, vhostfdSize); memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize); if (qemuInterfaceDirectConnect(vm->def, driver, net, tapfd, tapfdSize, @@ -1282,10 +1277,9 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, if (!tapfdSize) tapfdSize = vhostfdSize = 1; queueSize = tapfdSize; - if (VIR_ALLOC_N(tapfd, tapfdSize) < 0) - goto cleanup; + tapfd = g_new0(int, tapfdSize); memset(tapfd, -1, sizeof(*tapfd) * tapfdSize); - if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) + vhostfd = g_new0(int, vhostfdSize); goto cleanup;
^^^ Everything below here is unreachable. FWIW: Similar issues after g_new0 calls in: libxlCapsInitNuma libxlConnectDomainXMLToNative virStorageBackendISCSIDirectVolWipeZero virLoginShellGetShellArgv John
memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize); if (qemuInterfaceEthernetConnect(vm->def, driver, net, @@ -1381,9 +1375,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, goto cleanup; }
[...]

On a Tuesday in 2020, John Ferlan wrote:
Coverity notes ...
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 11b549b12b..09f8525cfa 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1282,10 +1277,9 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, if (!tapfdSize) tapfdSize = vhostfdSize = 1; queueSize = tapfdSize; - if (VIR_ALLOC_N(tapfd, tapfdSize) < 0) - goto cleanup; + tapfd = g_new0(int, tapfdSize); memset(tapfd, -1, sizeof(*tapfd) * tapfdSize); - if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) + vhostfd = g_new0(int, vhostfdSize); goto cleanup;
^^^ Everything below here is unreachable.
FWIW: Similar issues after g_new0 calls in:
libxlCapsInitNuma libxlConnectDomainXMLToNative virStorageBackendISCSIDirectVolWipeZero virLoginShellGetShellArgv
Thanks, patch sent. Jano
John
memset(vhostfd, -1, sizeof(*vhostfd) * vhostfdSize); if (qemuInterfaceEthernetConnect(vm->def, driver, net, @@ -1381,9 +1375,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, goto cleanup; }
[...]
participants (3)
-
Erik Skultety
-
John Ferlan
-
Ján Tomko