mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-09 01:04:59 +00:00
qemu: capabilities: use g_new0
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
868c350752
commit
f655a603dd
@ -943,14 +943,12 @@ virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
|
|||||||
*machines = NULL;
|
*machines = NULL;
|
||||||
*nmachines = accel->nmachineTypes;
|
*nmachines = accel->nmachineTypes;
|
||||||
|
|
||||||
if (*nmachines &&
|
if (*nmachines)
|
||||||
VIR_ALLOC_N(*machines, accel->nmachineTypes) < 0)
|
*machines = g_new0(virCapsGuestMachinePtr, accel->nmachineTypes);
|
||||||
goto error;
|
|
||||||
|
|
||||||
for (i = 0; i < accel->nmachineTypes; i++) {
|
for (i = 0; i < accel->nmachineTypes; i++) {
|
||||||
virCapsGuestMachinePtr mach;
|
virCapsGuestMachinePtr mach;
|
||||||
if (VIR_ALLOC(mach) < 0)
|
mach = g_new0(virCapsGuestMachine, 1);
|
||||||
goto error;
|
|
||||||
(*machines)[i] = mach;
|
(*machines)[i] = mach;
|
||||||
if (accel->machineTypes[i].alias) {
|
if (accel->machineTypes[i].alias) {
|
||||||
mach->name = g_strdup(accel->machineTypes[i].alias);
|
mach->name = g_strdup(accel->machineTypes[i].alias);
|
||||||
@ -985,8 +983,7 @@ virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
|
|||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
virCapsGuestMachinePtr mach;
|
virCapsGuestMachinePtr mach;
|
||||||
if (VIR_ALLOC(mach) < 0)
|
mach = g_new0(virCapsGuestMachine, 1);
|
||||||
goto error;
|
|
||||||
if (VIR_INSERT_ELEMENT_COPY(*machines, i, *nmachines, mach) < 0) {
|
if (VIR_INSERT_ELEMENT_COPY(*machines, i, *nmachines, mach) < 0) {
|
||||||
VIR_FREE(mach);
|
VIR_FREE(mach);
|
||||||
goto error;
|
goto error;
|
||||||
@ -1867,8 +1864,7 @@ virQEMUCapsSEVInfoCopy(virSEVCapabilityPtr *dst,
|
|||||||
{
|
{
|
||||||
g_autoptr(virSEVCapability) tmp = NULL;
|
g_autoptr(virSEVCapability) tmp = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(tmp) < 0)
|
tmp = g_new0(virSEVCapability, 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
tmp->pdh = g_strdup(src->pdh);
|
tmp->pdh = g_strdup(src->pdh);
|
||||||
tmp->cert_chain = g_strdup(src->cert_chain);
|
tmp->cert_chain = g_strdup(src->cert_chain);
|
||||||
@ -1949,8 +1945,7 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
|
|||||||
virQEMUCapsAccelCopy(&ret->tcg, &qemuCaps->tcg) < 0)
|
virQEMUCapsAccelCopy(&ret->tcg, &qemuCaps->tcg) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(ret->gicCapabilities, qemuCaps->ngicCapabilities) < 0)
|
ret->gicCapabilities = g_new0(virGICCapability, qemuCaps->ngicCapabilities);
|
||||||
goto error;
|
|
||||||
ret->ngicCapabilities = qemuCaps->ngicCapabilities;
|
ret->ngicCapabilities = qemuCaps->ngicCapabilities;
|
||||||
for (i = 0; i < qemuCaps->ngicCapabilities; i++)
|
for (i = 0; i < qemuCaps->ngicCapabilities; i++)
|
||||||
ret->gicCapabilities[i] = qemuCaps->gicCapabilities[i];
|
ret->gicCapabilities[i] = qemuCaps->gicCapabilities[i];
|
||||||
@ -3178,8 +3173,7 @@ virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps,
|
|||||||
if (!modelInfo)
|
if (!modelInfo)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(list, modelInfo->nprops + 1) < 0)
|
list = g_new0(char *, modelInfo->nprops + 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
for (i = 0; i < modelInfo->nprops; i++) {
|
for (i = 0; i < modelInfo->nprops; i++) {
|
||||||
@ -3555,8 +3549,7 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cpu->model = g_strdup(modelInfo->name);
|
cpu->model = g_strdup(modelInfo->name);
|
||||||
if (VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0)
|
cpu->features = g_new0(virCPUFeatureDef, modelInfo->nprops);
|
||||||
return -1;
|
|
||||||
|
|
||||||
cpu->nfeatures_max = modelInfo->nprops;
|
cpu->nfeatures_max = modelInfo->nprops;
|
||||||
cpu->nfeatures = 0;
|
cpu->nfeatures = 0;
|
||||||
@ -3866,8 +3859,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccelPtr caps,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(hostCPU) < 0)
|
hostCPU = g_new0(qemuMonitorCPUModelInfo, 1);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(hostCPU->name = virXMLPropString(hostCPUNode, "model"))) {
|
if (!(hostCPU->name = virXMLPropString(hostCPUNode, "model"))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -3888,9 +3880,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccelPtr caps,
|
|||||||
ctxt->node = hostCPUNode;
|
ctxt->node = hostCPUNode;
|
||||||
|
|
||||||
if ((n = virXPathNodeSet("./property", ctxt, &nodes)) > 0) {
|
if ((n = virXPathNodeSet("./property", ctxt, &nodes)) > 0) {
|
||||||
if (VIR_ALLOC_N(hostCPU->props, n) < 0)
|
hostCPU->props = g_new0(qemuMonitorCPUProperty, n);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
hostCPU->nprops = n;
|
hostCPU->nprops = n;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
@ -4035,8 +4025,7 @@ virQEMUCapsLoadCPUModels(virQEMUCapsAccelPtr caps,
|
|||||||
if (nblockers > 0) {
|
if (nblockers > 0) {
|
||||||
size_t j;
|
size_t j;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(cpu->blockers, nblockers + 1) < 0)
|
cpu->blockers = g_new0(char *, nblockers + 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (j = 0; j < nblockers; j++) {
|
for (j = 0; j < nblockers; j++) {
|
||||||
if (!(cpu->blockers[j] = virXMLPropString(blockerNodes[j], "name"))) {
|
if (!(cpu->blockers[j] = virXMLPropString(blockerNodes[j], "name"))) {
|
||||||
@ -4075,8 +4064,7 @@ virQEMUCapsLoadMachines(virQEMUCapsAccelPtr caps,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
caps->nmachineTypes = n;
|
caps->nmachineTypes = n;
|
||||||
if (VIR_ALLOC_N(caps->machineTypes, caps->nmachineTypes) < 0)
|
caps->machineTypes = g_new0(virQEMUCapsMachineType, caps->nmachineTypes);
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (!(caps->machineTypes[i].name = virXMLPropString(nodes[i], "name"))) {
|
if (!(caps->machineTypes[i].name = virXMLPropString(nodes[i], "name"))) {
|
||||||
@ -4183,8 +4171,7 @@ virQEMUCapsParseSEVInfo(virQEMUCapsPtr qemuCaps, xmlXPathContextPtr ctxt)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(sev) < 0)
|
sev = g_new0(virSEVCapability, 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (virXPathUInt("string(./sev/cbitpos)", ctxt, &sev->cbitpos) < 0) {
|
if (virXPathUInt("string(./sev/cbitpos)", ctxt, &sev->cbitpos) < 0) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
@ -4402,8 +4389,7 @@ virQEMUCapsLoadCache(virArch hostArch,
|
|||||||
bool boolValue;
|
bool boolValue;
|
||||||
|
|
||||||
qemuCaps->ngicCapabilities = n;
|
qemuCaps->ngicCapabilities = n;
|
||||||
if (VIR_ALLOC_N(qemuCaps->gicCapabilities, n) < 0)
|
qemuCaps->gicCapabilities = g_new0(virGICCapability, n);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
virGICCapabilityPtr cap = &qemuCaps->gicCapabilities[i];
|
virGICCapabilityPtr cap = &qemuCaps->gicCapabilities[i];
|
||||||
@ -5668,8 +5654,7 @@ virQEMUCapsCacheNew(const char *libDir,
|
|||||||
if (!(cache = virFileCacheNew(capsCacheDir, "xml", &qemuCapsCacheHandlers)))
|
if (!(cache = virFileCacheNew(capsCacheDir, "xml", &qemuCapsCacheHandlers)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (VIR_ALLOC(priv) < 0)
|
priv = g_new0(virQEMUCapsCachePriv, 1);
|
||||||
goto error;
|
|
||||||
virFileCacheSetPriv(cache, priv);
|
virFileCacheSetPriv(cache, priv);
|
||||||
|
|
||||||
priv->libDir = g_strdup(libDir);
|
priv->libDir = g_strdup(libDir);
|
||||||
@ -5893,8 +5878,7 @@ virQEMUCapsFillDomainLoaderCaps(virDomainCapsLoaderPtr capsLoader,
|
|||||||
capsLoader->readonly.report = true;
|
capsLoader->readonly.report = true;
|
||||||
capsLoader->secure.report = true;
|
capsLoader->secure.report = true;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(capsLoader->values.values, nfirmwares) < 0)
|
capsLoader->values.values = g_new0(char *, nfirmwares);
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (i = 0; i < nfirmwares; i++) {
|
for (i = 0; i < nfirmwares; i++) {
|
||||||
const char *filename = firmwares[i]->name;
|
const char *filename = firmwares[i]->name;
|
||||||
|
Loading…
Reference in New Issue
Block a user