Skip to content

Commit

Permalink
Do not check return value of VIR_REALLOC_N
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Denemark <[email protected]>
Reviewed-by: Erik Skultety <[email protected]>
  • Loading branch information
jirkade committed Mar 22, 2021
1 parent 52ef4a9 commit 1107c0b
Show file tree
Hide file tree
Showing 41 changed files with 96 additions and 205 deletions.
8 changes: 4 additions & 4 deletions src/bhyve/bhyve_parse_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,17 @@ bhyveCommandLineToArgv(const char *nativeConfig,
* Otherwise, later argument lists may be assigned to _argv without
* freeing the earlier ones. */
if (!_bhyve_argv && STREQ(arglist[0], "/usr/sbin/bhyve")) {
if ((VIR_REALLOC_N(_bhyve_argv, args_count + 1) < 0)
|| (!bhyve_argc))
VIR_REALLOC_N(_bhyve_argv, args_count + 1);
if (!bhyve_argc)
goto error;
for (j = 0; j < args_count; j++)
_bhyve_argv[j] = arglist[j];
_bhyve_argv[j] = NULL;
*bhyve_argc = args_count-1;
VIR_FREE(arglist);
} else if (!_loader_argv) {
if ((VIR_REALLOC_N(_loader_argv, args_count + 1) < 0)
|| (!loader_argc))
VIR_REALLOC_N(_loader_argv, args_count + 1);
if (!loader_argc)
goto error;
for (j = 0; j < args_count; j++)
_loader_argv[j] = arglist[j];
Expand Down
3 changes: 1 addition & 2 deletions src/conf/capabilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,8 +1476,7 @@ virCapabilitiesGetNUMASiblingInfo(int node,
tmp_size++;
}

if (VIR_REALLOC_N(tmp, tmp_size) < 0)
goto cleanup;
VIR_REALLOC_N(tmp, tmp_size);

*nsiblings = tmp_size;
*siblings = g_steal_pointer(&tmp);
Expand Down
11 changes: 6 additions & 5 deletions src/conf/domain_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3433,8 +3433,7 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def,
def->iothreadids[i]->iothread_id));

/* resize array */
if (VIR_REALLOC_N(def->iothreadids, iothreads) < 0)
return -1;
VIR_REALLOC_N(def->iothreadids, iothreads);

/* Populate iothreadids[] using the set bit number from thrmap */
while (def->niothreadids < iothreads) {
Expand Down Expand Up @@ -17587,7 +17586,8 @@ virDomainChrPreAlloc(virDomainDefPtr vmdef,
&arrPtr, &cntPtr) < 0)
return -1;

return VIR_REALLOC_N(*arrPtr, *cntPtr + 1);
VIR_REALLOC_N(*arrPtr, *cntPtr + 1);
return 0;
}

void
Expand Down Expand Up @@ -21442,8 +21442,9 @@ virDomainDefParseXML(xmlDocPtr xml,
/* analysis of the host devices */
if ((n = virXPathNodeSet("./devices/hostdev", ctxt, &nodes)) < 0)
goto error;
if (n && VIR_REALLOC_N(def->hostdevs, def->nhostdevs + n) < 0)
goto error;
if (n > 0)
VIR_REALLOC_N(def->hostdevs, def->nhostdevs + n);

for (i = 0; i < n; i++) {
virDomainHostdevDefPtr hostdev;

Expand Down
3 changes: 1 addition & 2 deletions src/conf/storage_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1787,8 +1787,7 @@ virStoragePoolSourceListNewSource(virStoragePoolSourceListPtr list)
{
virStoragePoolSourcePtr source;

if (VIR_REALLOC_N(list->sources, list->nsources + 1) < 0)
return NULL;
VIR_REALLOC_N(list->sources, list->nsources + 1);

source = &list->sources[list->nsources++];
memset(source, 0, sizeof(*source));
Expand Down
2 changes: 1 addition & 1 deletion src/conf/virinterfaceobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ virInterfaceObjListExport(virConnectPtr conn,

if (data.ifaces) {
/* trim the array to the final size */
ignore_value(VIR_REALLOC_N(data.ifaces, data.nifaces + 1));
VIR_REALLOC_N(data.ifaces, data.nifaces + 1);
*ifaces = data.ifaces;
data.ifaces = NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions src/conf/virnetworkobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ virNetworkObjListExport(virConnectPtr conn,

if (data.nets) {
/* trim the array to the final size */
ignore_value(VIR_REALLOC_N(data.nets, data.nnets + 1));
VIR_REALLOC_N(data.nets, data.nnets + 1);
*nets = data.nets;
data.nets = NULL;
}
Expand Down Expand Up @@ -1816,7 +1816,7 @@ virNetworkObjPortListExport(virNetworkPtr net,

if (data.ports) {
/* trim the array to the final size */
ignore_value(VIR_REALLOC_N(data.ports, data.nports + 1));
VIR_REALLOC_N(data.ports, data.nports + 1);
*ports = data.ports;
data.ports = NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/conf/virnodedeviceobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ virNodeDeviceObjListExport(virConnectPtr conn,
goto cleanup;

if (data.devices) {
ignore_value(VIR_REALLOC_N(data.devices, data.ndevices + 1));
VIR_REALLOC_N(data.devices, data.ndevices + 1);
*devices = data.devices;
}

Expand Down
2 changes: 1 addition & 1 deletion src/conf/virsecretobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ virSecretObjListExport(virConnectPtr conn,

if (data.secrets) {
/* trim the array to the final size */
ignore_value(VIR_REALLOC_N(data.secrets, data.nsecrets + 1));
VIR_REALLOC_N(data.secrets, data.nsecrets + 1);
*secrets = data.secrets;
}

Expand Down
2 changes: 1 addition & 1 deletion src/conf/virstorageobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ virStoragePoolObjListExport(virConnectPtr conn,

if (data.pools) {
/* trim the array to the final size */
ignore_value(VIR_REALLOC_N(data.pools, data.nPools + 1));
VIR_REALLOC_N(data.pools, data.nPools + 1);
*pools = data.pools;
}

Expand Down
3 changes: 1 addition & 2 deletions src/esx/esx_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ esxVI_CURL_WriteStream(char *input, size_t size, size_t nmemb, void *userdata)
} else if (input_remaining > backlog_remaining) {
priv->backlog_size += input_remaining - backlog_remaining;

if (VIR_REALLOC_N(priv->backlog, priv->backlog_size) < 0)
return 0;
VIR_REALLOC_N(priv->backlog, priv->backlog_size);
}

memcpy(priv->backlog + priv->backlog_used, input + input_used,
Expand Down
2 changes: 1 addition & 1 deletion src/interface/interface_backend_netcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,

if (tmp_iface_objs) {
/* trim the array to the final size */
ignore_value(VIR_REALLOC_N(tmp_iface_objs, niface_objs + 1));
VIR_REALLOC_N(tmp_iface_objs, niface_objs + 1);
*ifaces = g_steal_pointer(&tmp_iface_objs);
}

Expand Down
2 changes: 1 addition & 1 deletion src/interface/interface_backend_udev.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,

/* Trim the array to its final size */
if (ifaces) {
ignore_value(VIR_REALLOC_N(ifaces_list, count + 1));
VIR_REALLOC_N(ifaces_list, count + 1);
*ifaces = g_steal_pointer(&ifaces_list);
}

Expand Down
3 changes: 1 addition & 2 deletions src/libxl/libxl_capabilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps)
if (nr_cpus_node[node] == 1) {
cpus[node] = g_new0(virCapsHostNUMACellCPU, 1);
} else {
if (VIR_REALLOC_N(cpus[node], nr_cpus_node[node]) < 0)
goto cleanup;
VIR_REALLOC_N(cpus[node], nr_cpus_node[node]);
}

/* Mapping between what libxl tells and what libvirt wants */
Expand Down
14 changes: 5 additions & 9 deletions src/libxl/libxl_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1751,9 +1751,10 @@ libxlDriverConfigNew(void)
#ifdef DEFAULT_LOADER_NVRAM
if (virFirmwareParseList(DEFAULT_LOADER_NVRAM,
&cfg->firmwares,
&cfg->nfirmwares) < 0)
goto error;

&cfg->nfirmwares) < 0) {
virObjectUnref(cfg);
return NULL;
}
#else
cfg->firmwares = g_new0(virFirmwarePtr, 1);
cfg->nfirmwares = 1;
Expand All @@ -1762,8 +1763,7 @@ libxlDriverConfigNew(void)
#endif

/* Always add hvmloader to firmwares */
if (VIR_REALLOC_N(cfg->firmwares, cfg->nfirmwares + 1) < 0)
goto error;
VIR_REALLOC_N(cfg->firmwares, cfg->nfirmwares + 1);
cfg->nfirmwares++;
cfg->firmwares[cfg->nfirmwares - 1] = g_new0(virFirmware, 1);
cfg->firmwares[cfg->nfirmwares - 1]->name = g_strdup(LIBXL_FIRMWARE_DIR "/hvmloader");
Expand All @@ -1773,10 +1773,6 @@ libxlDriverConfigNew(void)
cfg->keepAliveCount = 5;

return cfg;

error:
virObjectUnref(cfg);
return NULL;
}

int
Expand Down
15 changes: 5 additions & 10 deletions src/libxl/libxl_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3054,8 +3054,7 @@ libxlDomainAttachDeviceDiskLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev)
goto cleanup;
}

if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1);

if (libxlMakeDisk(l_disk, &x_disk) < 0)
goto cleanup;
Expand Down Expand Up @@ -3122,8 +3121,7 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
goto cleanup;
}

if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1);

if (virHostdevPreparePCIDevices(hostdev_mgr, LIBXL_DRIVER_INTERNAL_NAME,
vm->def->name, vm->def->uuid,
Expand Down Expand Up @@ -3190,8 +3188,7 @@ libxlDomainAttachControllerDevice(libxlDriverPrivatePtr driver,
goto cleanup;
}

if (VIR_REALLOC_N(vm->def->controllers, vm->def->ncontrollers + 1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->controllers, vm->def->ncontrollers + 1);

if (libxlMakeUSBController(controller, &usbctrl) < 0)
goto cleanup;
Expand Down Expand Up @@ -3259,8 +3256,7 @@ libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr driver,
}
}

if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1);

if (virHostdevPrepareUSBDevices(hostdev_mgr, LIBXL_DRIVER_INTERNAL_NAME,
vm->def->name, &hostdev, 1, 0) < 0)
Expand Down Expand Up @@ -3403,8 +3399,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
libxl_device_nic_init(&nic);

/* preallocate new slot for device */
if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1);

/* If appropriate, grab a physical device from the configured
* network's pool of devices, or resolve bridge device name
Expand Down
4 changes: 1 addition & 3 deletions src/qemu/qemu_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,7 @@ qemuAgentIORead(qemuAgentPtr agent)
QEMU_AGENT_MAX_RESPONSE);
return -1;
}
if (VIR_REALLOC_N(agent->buffer,
agent->bufferLength + 1024) < 0)
return -1;
VIR_REALLOC_N(agent->buffer, agent->bufferLength + 1024);
agent->bufferLength += 1024;
avail += 1024;
}
Expand Down
5 changes: 2 additions & 3 deletions src/qemu/qemu_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -1464,9 +1464,8 @@ qemuFirmwareGetSupported(const char *machine,
}
}

if (fws && !*fws && nfirmwares &&
VIR_REALLOC_N(*fws, 0) < 0)
return -1;
if (fws && !*fws && nfirmwares)
VIR_REALLOC_N(*fws, 0);

for (i = 0; i < nfirmwares; i++)
qemuFirmwareFree(firmwares[i]);
Expand Down
36 changes: 12 additions & 24 deletions src/qemu/qemu_hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
if (!(devstr = qemuBuildDiskDeviceStr(vm->def, disk, 0, priv->qemuCaps)))
goto cleanup;

if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1);

if (qemuHotplugAttachManagedPR(driver, vm, disk->src, QEMU_ASYNC_JOB_NONE) < 0)
goto cleanup;
Expand Down Expand Up @@ -880,8 +879,7 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
if (!devstr)
goto cleanup;

if (VIR_REALLOC_N(vm->def->controllers, vm->def->ncontrollers+1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->controllers, vm->def->ncontrollers+1);

qemuDomainObjEnterMonitor(driver, vm);

Expand Down Expand Up @@ -1198,8 +1196,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
virErrorPtr save_err = NULL;

/* preallocate new slot for device */
if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1);

/* If appropriate, grab a physical device from the configured
* network's pool of devices, or resolve bridge device name
Expand Down Expand Up @@ -1604,8 +1601,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
unsigned int flags = 0;

if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
return -1;
VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1);

if (!cfg->relaxedACS)
flags |= VIR_HOSTDEV_STRICT_ACS_CHECK;
Expand Down Expand Up @@ -1938,8 +1934,7 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
if (!(devstr = qemuBuildRedirdevDevStr(def, redirdev, priv->qemuCaps)))
goto cleanup;

if (VIR_REALLOC_N(def->redirdevs, def->nredirdevs+1) < 0)
goto cleanup;
VIR_REALLOC_N(def->redirdevs, def->nredirdevs+1);

if (qemuDomainAddChardevTLSObjects(driver, vm, redirdev->source,
redirdev->info.alias, charAlias,
Expand Down Expand Up @@ -2286,8 +2281,7 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
goto cleanup;

/* preallocate space for the device definition */
if (VIR_REALLOC_N(vm->def->rngs, vm->def->nrngs + 1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->rngs, vm->def->nrngs + 1);

if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev, "rng") < 0)
return -1;
Expand Down Expand Up @@ -2569,8 +2563,7 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
if (!(devstr = qemuBuildUSBHostdevDevStr(vm->def, hostdev, priv->qemuCaps)))
goto cleanup;

if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1);

qemuDomainObjEnterMonitor(driver, vm);
ret = qemuMonitorAddDevice(priv->mon, devstr);
Expand Down Expand Up @@ -2662,8 +2655,7 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriverPtr driver,
if (!(devstr = qemuBuildSCSIHostdevDevStr(vm->def, hostdev, backendalias)))
goto cleanup;

if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1);

qemuDomainObjEnterMonitor(driver, vm);

Expand Down Expand Up @@ -2774,8 +2766,7 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriverPtr driver,
vhostfdName)))
goto cleanup;

if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1);

qemuDomainObjEnterMonitor(driver, vm);

Expand Down Expand Up @@ -2877,8 +2868,7 @@ qemuDomainAttachMediatedDevice(virQEMUDriverPtr driver,
priv->qemuCaps)))
goto cleanup;

if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1);

if (qemuDomainAdjustMaxMemLockHostdev(vm, hostdev) < 0)
goto cleanup;
Expand Down Expand Up @@ -3006,8 +2996,7 @@ qemuDomainAttachShmemDevice(virQEMUDriverPtr driver,

qemuDomainPrepareShmemChardev(shmem);

if (VIR_REALLOC_N(vm->def->shmems, vm->def->nshmems + 1) < 0)
return -1;
VIR_REALLOC_N(vm->def->shmems, vm->def->nshmems + 1);

if ((shmem->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
shmem->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) &&
Expand Down Expand Up @@ -3209,8 +3198,7 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver,
goto cleanup;
teardownlabel = true;

if (VIR_REALLOC_N(vm->def->inputs, vm->def->ninputs + 1) < 0)
goto cleanup;
VIR_REALLOC_N(vm->def->inputs, vm->def->ninputs + 1);

qemuDomainObjEnterMonitor(driver, vm);

Expand Down
Loading

0 comments on commit 1107c0b

Please sign in to comment.