mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
qemu: 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
73f7b6a0ef
commit
7d77fdb90f
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -640,9 +640,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],
|
||||
@ -839,12 +838,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;
|
||||
}
|
||||
@ -1348,8 +1346,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];
|
||||
@ -1615,9 +1612,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);
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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))) {
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
@ -3684,11 +3683,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);
|
||||
|
||||
@ -3719,10 +3716,6 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig)
|
||||
}
|
||||
|
||||
return copy;
|
||||
|
||||
error:
|
||||
qemuMonitorCPUModelInfoFree(copy);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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])))
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user