Do not check return value of VIR_EXPAND_N

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Jiri Denemark 2021-03-20 00:37:03 +01:00
parent ea5e926bb6
commit 7d2fd6ef01
45 changed files with 106 additions and 306 deletions

View File

@ -40,8 +40,7 @@ int virAccessDriverStackAppend(virAccessManagerPtr manager,
{ {
virAccessDriverStackPrivatePtr priv = virAccessManagerGetPrivateData(manager); virAccessDriverStackPrivatePtr priv = virAccessManagerGetPrivateData(manager);
if (VIR_EXPAND_N(priv->managers, priv->managersLen, 1) < 0) VIR_EXPAND_N(priv->managers, priv->managersLen, 1);
return -1;
priv->managers[priv->managersLen-1] = child; priv->managers[priv->managersLen-1] = child;

View File

@ -554,8 +554,7 @@ virDomainBackupAlignDisks(virDomainBackupDefPtr def,
backup_all = true; backup_all = true;
ndisks = def->ndisks; ndisks = def->ndisks;
if (VIR_EXPAND_N(def->disks, def->ndisks, dom->ndisks - def->ndisks) < 0) VIR_EXPAND_N(def->disks, def->ndisks, dom->ndisks - def->ndisks);
return -1;
for (i = 0; i < dom->ndisks; i++) { for (i = 0; i < dom->ndisks; i++) {
virDomainBackupDiskDefPtr backupdisk = NULL; virDomainBackupDiskDefPtr backupdisk = NULL;

View File

@ -580,9 +580,7 @@ virCapabilitiesHostSecModelAddBaseLabel(virCapsHostSecModelPtr secmodel,
if (type == NULL || label == NULL) if (type == NULL || label == NULL)
return -1; return -1;
if (VIR_EXPAND_N(secmodel->labels, secmodel->nlabels, 1) < 0) VIR_EXPAND_N(secmodel->labels, secmodel->nlabels, 1);
return -1;
secmodel->labels[secmodel->nlabels - 1].type = g_strdup(type); secmodel->labels[secmodel->nlabels - 1].type = g_strdup(type);
secmodel->labels[secmodel->nlabels - 1].label = g_strdup(label); secmodel->labels[secmodel->nlabels - 1].label = g_strdup(label);

View File

@ -728,8 +728,7 @@ virDomainPCIAddressSetGrow(virDomainPCIAddressSetPtr addrs,
i = addrs->nbuses; i = addrs->nbuses;
if (VIR_EXPAND_N(addrs->buses, addrs->nbuses, add) < 0) VIR_EXPAND_N(addrs->buses, addrs->nbuses, add);
return -1;
if (needDMIToPCIBridge) { if (needDMIToPCIBridge) {
/* first of the new buses is dmi-to-pci-bridge, the /* first of the new buses is dmi-to-pci-bridge, the
@ -1985,8 +1984,7 @@ virDomainUSBAddressSetAddController(virDomainUSBAddressSetPtr addrs,
return 0; return 0;
if (addrs->nbuses <= cont->idx) { if (addrs->nbuses <= cont->idx) {
if (VIR_EXPAND_N(addrs->buses, addrs->nbuses, cont->idx - addrs->nbuses + 1) < 0) VIR_EXPAND_N(addrs->buses, addrs->nbuses, cont->idx - addrs->nbuses + 1);
goto cleanup;
} else if (addrs->buses[cont->idx]) { } else if (addrs->buses[cont->idx]) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("Duplicate USB controllers with index %u"), _("Duplicate USB controllers with index %u"),

View File

@ -2001,8 +2001,7 @@ virDomainDefSetVcpusMax(virDomainDefPtr def,
return 0; return 0;
if (def->maxvcpus < maxvcpus) { if (def->maxvcpus < maxvcpus) {
if (VIR_EXPAND_N(def->vcpus, def->maxvcpus, maxvcpus - def->maxvcpus) < 0) VIR_EXPAND_N(def->vcpus, def->maxvcpus, maxvcpus - def->maxvcpus);
return -1;
for (i = oldmax; i < def->maxvcpus; i++) { for (i = oldmax; i < def->maxvcpus; i++) {
if (!(def->vcpus[i] = virDomainVcpuDefNew(xmlopt))) if (!(def->vcpus[i] = virDomainVcpuDefNew(xmlopt)))

View File

@ -381,11 +381,7 @@ virNWFilterRuleDefAddVar(virNWFilterRuleDefPtr nwf,
} }
} }
if (VIR_EXPAND_N(nwf->varAccess, nwf->nVarAccess, 1) < 0) { VIR_EXPAND_N(nwf->varAccess, nwf->nVarAccess, 1);
virNWFilterVarAccessFree(varAccess);
return -1;
}
nwf->varAccess[nwf->nVarAccess - 1] = varAccess; nwf->varAccess[nwf->nVarAccess - 1] = varAccess;
item->varAccess = varAccess; item->varAccess = varAccess;

View File

@ -221,9 +221,7 @@ virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value)
break; break;
case NWFILTER_VALUE_TYPE_ARRAY: case NWFILTER_VALUE_TYPE_ARRAY:
if (VIR_EXPAND_N(val->u.array.values, VIR_EXPAND_N(val->u.array.values, val->u.array.nValues, 1);
val->u.array.nValues, 1) < 0)
return -1;
val->u.array.values[val->u.array.nValues - 1] = value; val->u.array.values[val->u.array.nValues - 1] = value;
rc = 0; rc = 0;
break; break;
@ -374,9 +372,7 @@ virNWFilterVarCombIterAddVariable(virNWFilterVarCombIterEntryPtr cie,
} }
} }
if (VIR_EXPAND_N(cie->varNames, cie->nVarNames, 1) < 0) VIR_EXPAND_N(cie->varNames, cie->nVarNames, 1);
return -1;
cie->varNames[cie->nVarNames - 1] = varName; cie->varNames[cie->nVarNames - 1] = varName;
return 0; return 0;

View File

@ -5144,9 +5144,7 @@ esxDomainInterfaceAddresses(virDomainPtr domain,
continue; continue;
} }
if (VIR_EXPAND_N(ifaces_ret, ifaces_count, 1) < 0) VIR_EXPAND_N(ifaces_ret, ifaces_count, 1);
goto cleanup;
ifaces_ret[ifaces_count - 1] = g_new0(virDomainInterface, 1); ifaces_ret[ifaces_count - 1] = g_new0(virDomainInterface, 1);
iface = ifaces_ret[ifaces_count - 1]; iface = ifaces_ret[ifaces_count - 1];

View File

@ -189,8 +189,7 @@ static inline int
hypervCheckParams(hypervInvokeParamsListPtr params) hypervCheckParams(hypervInvokeParamsListPtr params)
{ {
if (params->nbParams + 1 > params->nbAvailParams) { if (params->nbParams + 1 > params->nbAvailParams) {
if (VIR_EXPAND_N(params->params, params->nbAvailParams, 5) < 0) VIR_EXPAND_N(params->params, params->nbAvailParams, 5);
return -1;
} }
return 0; return 0;

View File

@ -161,8 +161,7 @@ virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *dest_array,
if (!found) { if (!found) {
if (!src->weight && !src->riops && !src->wiops && !src->rbps && !src->wbps) if (!src->weight && !src->riops && !src->wiops && !src->rbps && !src->wbps)
continue; continue;
if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0) VIR_EXPAND_N(*dest_array, *dest_size, 1);
return -1;
dest = &(*dest_array)[*dest_size - 1]; dest = &(*dest_array)[*dest_size - 1];
if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {

View File

@ -262,7 +262,7 @@ virCloseCallbacksGetOne(void *payload,
if (data->conn != closeDef->conn || !closeDef->cb) if (data->conn != closeDef->conn || !closeDef->cb)
return 0; return 0;
ignore_value(VIR_EXPAND_N(data->list->entries, data->list->nentries, 1)); VIR_EXPAND_N(data->list->entries, data->list->nentries, 1);
memcpy(data->list->entries[data->list->nentries - 1].uuid, memcpy(data->list->entries[data->list->nentries - 1].uuid,
uuid, VIR_UUID_BUFLEN); uuid, VIR_UUID_BUFLEN);

View File

@ -651,8 +651,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
continue; continue;
#ifdef LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST #ifdef LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST
if (VIR_EXPAND_N(b_info->u.hvm.usbdevice_list, nusbdevice, 1) < 0) VIR_EXPAND_N(b_info->u.hvm.usbdevice_list, nusbdevice, 1);
return -1;
#else #else
nusbdevice++; nusbdevice++;
if (nusbdevice > 1) { if (nusbdevice > 1) {
@ -685,10 +684,8 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
#ifdef LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST #ifdef LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST
/* NULL-terminate usbdevice_list */ /* NULL-terminate usbdevice_list */
if (nusbdevice > 0 && if (nusbdevice > 0)
VIR_EXPAND_N(b_info->u.hvm.usbdevice_list, nusbdevice, 1) < 0) { VIR_EXPAND_N(b_info->u.hvm.usbdevice_list, nusbdevice, 1);
return -1;
}
#endif #endif
} else if (pvh) { } else if (pvh) {
b_info->cmdline = g_strdup(def->os.cmdline); b_info->cmdline = g_strdup(def->os.cmdline);

View File

@ -552,8 +552,7 @@ xenParseHypervisorFeatures(virConfPtr conf, virDomainDefPtr def)
return -1; return -1;
if (strval) { if (strval) {
if (VIR_EXPAND_N(def->clock.timers, def->clock.ntimers, 1) < 0) VIR_EXPAND_N(def->clock.timers, def->clock.ntimers, 1);
return -1;
timer = g_new0(virDomainTimerDef, 1); timer = g_new0(virDomainTimerDef, 1);
timer->name = VIR_DOMAIN_TIMER_NAME_TSC; timer->name = VIR_DOMAIN_TIMER_NAME_TSC;
@ -625,8 +624,7 @@ xenParseHypervisorFeatures(virConfPtr conf, virDomainDefPtr def)
return -1; return -1;
if (val != -1) { if (val != -1) {
if (VIR_EXPAND_N(def->clock.timers, def->clock.ntimers, 1) < 0) VIR_EXPAND_N(def->clock.timers, def->clock.ntimers, 1);
return -1;
timer = g_new0(virDomainTimerDef, 1); timer = g_new0(virDomainTimerDef, 1);
timer->name = VIR_DOMAIN_TIMER_NAME_HPET; timer->name = VIR_DOMAIN_TIMER_NAME_HPET;

View File

@ -641,9 +641,7 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
goto cleanup; goto cleanup;
} }
if (VIR_EXPAND_N(priv->resources, priv->nresources, 1) < 0) VIR_EXPAND_N(priv->resources, priv->nresources, 1);
goto cleanup;
priv->resources[priv->nresources-1].lockspace = g_steal_pointer(&newLockspace); priv->resources[priv->nresources-1].lockspace = g_steal_pointer(&newLockspace);
priv->resources[priv->nresources-1].name = g_steal_pointer(&newName); priv->resources[priv->nresources-1].name = g_steal_pointer(&newName);

View File

@ -321,8 +321,7 @@ static void virLXCControllerFree(virLXCControllerPtr ctrl)
static int virLXCControllerAddConsole(virLXCControllerPtr ctrl, static int virLXCControllerAddConsole(virLXCControllerPtr ctrl,
int hostFd) int hostFd)
{ {
if (VIR_EXPAND_N(ctrl->consoles, ctrl->nconsoles, 1) < 0) VIR_EXPAND_N(ctrl->consoles, ctrl->nconsoles, 1);
return -1;
ctrl->consoles[ctrl->nconsoles-1].daemon = ctrl->daemon; ctrl->consoles[ctrl->nconsoles-1].daemon = ctrl->daemon;
ctrl->consoles[ctrl->nconsoles-1].hostFd = hostFd; ctrl->consoles[ctrl->nconsoles-1].hostFd = hostFd;
ctrl->consoles[ctrl->nconsoles-1].hostWatch = -1; ctrl->consoles[ctrl->nconsoles-1].hostWatch = -1;
@ -402,10 +401,7 @@ static int virLXCControllerGetNICIndexes(virLXCControllerPtr ctrl)
if (virNetDevGetIndex(ctrl->def->nets[i]->ifname, if (virNetDevGetIndex(ctrl->def->nets[i]->ifname,
&nicindex) < 0) &nicindex) < 0)
return -1; return -1;
if (VIR_EXPAND_N(ctrl->nicindexes, VIR_EXPAND_N(ctrl->nicindexes, ctrl->nnicindexes, 1);
ctrl->nnicindexes,
1) < 0)
return -1;
VIR_DEBUG("Index %d for %s", nicindex, VIR_DEBUG("Index %d for %s", nicindex,
ctrl->def->nets[i]->ifname); ctrl->def->nets[i]->ifname);
ctrl->nicindexes[ctrl->nnicindexes-1] = nicindex; ctrl->nicindexes[ctrl->nnicindexes-1] = nicindex;
@ -636,10 +632,7 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
return -1; return -1;
VIR_DEBUG("Saving loop fd %d", fd); VIR_DEBUG("Saving loop fd %d", fd);
if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) { VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1);
VIR_FORCE_CLOSE(fd);
return -1;
}
ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd; ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
} else if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_NBD) { } else if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_NBD) {
if (virLXCControllerSetupNBDDeviceFS(fs) < 0) if (virLXCControllerSetupNBDDeviceFS(fs) < 0)
@ -694,10 +687,7 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
return -1; return -1;
VIR_DEBUG("Saving loop fd %d", fd); VIR_DEBUG("Saving loop fd %d", fd);
if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) { VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1);
VIR_FORCE_CLOSE(fd);
return -1;
}
ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd; ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
} else if (!driver || STREQ(driver, "nbd")) { } else if (!driver || STREQ(driver, "nbd")) {
if (disk->cachemode != VIR_DOMAIN_DISK_CACHE_DEFAULT && if (disk->cachemode != VIR_DOMAIN_DISK_CACHE_DEFAULT &&

View File

@ -123,16 +123,13 @@ static char ** lxcStringSplit(const char *string)
goto error; goto error;
/* Append NULL element */ /* Append NULL element */
if (VIR_EXPAND_N(result, ntokens, 1) < 0) VIR_EXPAND_N(result, ntokens, 1);
goto error;
for (i = 0; parts[i]; i++) { for (i = 0; parts[i]; i++) {
if (STREQ(parts[i], "")) if (STREQ(parts[i], ""))
continue; continue;
if (VIR_EXPAND_N(result, ntokens, 1) < 0) VIR_EXPAND_N(result, ntokens, 1);
goto error;
result[ntokens - 2] = g_strdup(parts[i]); result[ntokens - 2] = g_strdup(parts[i]);
} }
@ -189,8 +186,7 @@ lxcAddFSDef(virDomainDefPtr def,
if (!(fsDef = lxcCreateFSDef(type, src, dst, readonly, usage))) if (!(fsDef = lxcCreateFSDef(type, src, dst, readonly, usage)))
goto error; goto error;
if (VIR_EXPAND_N(def->fss, def->nfss, 1) < 0) VIR_EXPAND_N(def->fss, def->nfss, 1);
goto error;
def->fss[def->nfss - 1] = fsDef; def->fss[def->nfss - 1] = fsDef;
return 0; return 0;
@ -509,8 +505,7 @@ lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetworkParseData *data)
&hostdev->source.caps.u.net.ip.nroutes) < 0) &hostdev->source.caps.u.net.ip.nroutes) < 0)
goto error; goto error;
if (VIR_EXPAND_N(def->hostdevs, def->nhostdevs, 1) < 0) VIR_EXPAND_N(def->hostdevs, def->nhostdevs, 1);
goto error;
def->hostdevs[def->nhostdevs - 1] = hostdev; def->hostdevs[def->nhostdevs - 1] = hostdev;
} else { } else {
if (!(net = lxcCreateNetDef(data->type, data->link, data->mac, if (!(net = lxcCreateNetDef(data->type, data->link, data->mac,
@ -533,8 +528,7 @@ lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetworkParseData *data)
&net->guestIP.nroutes) < 0) &net->guestIP.nroutes) < 0)
goto error; goto error;
if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0) VIR_EXPAND_N(def->nets, def->nnets, 1);
goto error;
def->nets[def->nnets - 1] = net; def->nets[def->nnets - 1] = net;
} }
@ -651,9 +645,7 @@ lxcNetworkGetParseDataByIndex(lxcNetworkParseDataArray *networks,
/* Index was not found. So, it is time to add new * /* Index was not found. So, it is time to add new *
* interface and return this last position. */ * interface and return this last position. */
if (VIR_EXPAND_N(networks->parseData, networks->ndata, 1) < 0) VIR_EXPAND_N(networks->parseData, networks->ndata, 1);
return NULL;
networks->parseData[ndata] = g_new0(lxcNetworkParseData, 1); networks->parseData[ndata] = g_new0(lxcNetworkParseData, 1);
networks->parseData[ndata]->index = index; networks->parseData[ndata]->index = index;
@ -696,9 +688,7 @@ lxcNetworkGetParseDataByIndexLegacy(lxcNetworkParseDataArray *networks,
if (elem == VIR_LXC_NETWORK_CONFIG_TYPE) { if (elem == VIR_LXC_NETWORK_CONFIG_TYPE) {
/* Index was not found. So, it is time to add new * /* Index was not found. So, it is time to add new *
* interface and return this last position. */ * interface and return this last position. */
if (VIR_EXPAND_N(networks->parseData, networks->ndata, 1) < 0) VIR_EXPAND_N(networks->parseData, networks->ndata, 1);
return NULL;
networks->parseData[ndata] = g_new0(lxcNetworkParseData, 1); networks->parseData[ndata] = g_new0(lxcNetworkParseData, 1);
networks->parseData[ndata]->index = networks->ndata; networks->parseData[ndata]->index = networks->ndata;
@ -858,12 +848,10 @@ lxcIdmapWalkCallback(const char *name, virConfValuePtr value, void *data)
} }
if (type == 'u') { if (type == 'u') {
if (VIR_EXPAND_N(def->idmap.uidmap, def->idmap.nuidmap, 1) < 0) VIR_EXPAND_N(def->idmap.uidmap, def->idmap.nuidmap, 1);
return -1;
idmap = &def->idmap.uidmap[def->idmap.nuidmap - 1]; idmap = &def->idmap.uidmap[def->idmap.nuidmap - 1];
} else if (type == 'g') { } else if (type == 'g') {
if (VIR_EXPAND_N(def->idmap.gidmap, def->idmap.ngidmap, 1) < 0) VIR_EXPAND_N(def->idmap.gidmap, def->idmap.ngidmap, 1);
return -1;
idmap = &def->idmap.gidmap[def->idmap.ngidmap - 1]; idmap = &def->idmap.gidmap[def->idmap.ngidmap - 1];
} else { } else {
return -1; return -1;
@ -1017,8 +1005,7 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValuePtr value, void *data)
device = &def->blkio.devices[i]; device = &def->blkio.devices[i];
} }
if (!device) { if (!device) {
if (VIR_EXPAND_N(def->blkio.devices, def->blkio.ndevices, 1) < 0) VIR_EXPAND_N(def->blkio.devices, def->blkio.ndevices, 1);
goto cleanup;
device = &def->blkio.devices[def->blkio.ndevices - 1]; device = &def->blkio.devices[def->blkio.ndevices - 1];
device->path = path; device->path = path;
path = NULL; path = NULL;

View File

@ -2160,8 +2160,7 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePtr **ifaces_ret,
/* If the hash table doesn't contain this iface, add it */ /* If the hash table doesn't contain this iface, add it */
if (!iface) { if (!iface) {
if (VIR_EXPAND_N(*ifaces_ret, *ifaces_count, 1) < 0) VIR_EXPAND_N(*ifaces_ret, *ifaces_count, 1);
return -1;
iface = g_new0(virDomainInterface, 1); iface = g_new0(virDomainInterface, 1);
(*ifaces_ret)[*ifaces_count - 1] = iface; (*ifaces_ret)[*ifaces_count - 1] = iface;
@ -2191,9 +2190,7 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePtr **ifaces_ret,
/* If current iface already exists, continue with the count */ /* If current iface already exists, continue with the count */
addrs_count = iface->naddrs; addrs_count = iface->naddrs;
if (VIR_EXPAND_N(iface->addrs, addrs_count, VIR_EXPAND_N(iface->addrs, addrs_count, virJSONValueArraySize(ip_addr_arr));
virJSONValueArraySize(ip_addr_arr)) < 0)
return -1;
for (j = 0; j < virJSONValueArraySize(ip_addr_arr); j++) { for (j = 0; j < virJSONValueArraySize(ip_addr_arr); j++) {
virJSONValuePtr ip_addr_obj = virJSONValueArrayGet(ip_addr_arr, j); virJSONValuePtr ip_addr_obj = virJSONValueArrayGet(ip_addr_arr, j);

View File

@ -2166,8 +2166,7 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
if (defs) { if (defs) {
start = defs->ncpus; start = defs->ncpus;
if (VIR_EXPAND_N(defs->cpus, defs->ncpus, count) < 0) VIR_EXPAND_N(defs->cpus, defs->ncpus, count);
return -1;
} else { } else {
start = 0; start = 0;

View File

@ -1597,11 +1597,7 @@ qemuSharedDeviceEntryInsert(virQEMUDriverPtr driver,
* recorded in the table. * recorded in the table.
*/ */
if (!qemuSharedDeviceEntryDomainExists(entry, name, NULL)) { if (!qemuSharedDeviceEntryDomainExists(entry, name, NULL)) {
if (VIR_EXPAND_N(entry->domains, entry->ref, 1) < 0) { VIR_EXPAND_N(entry->domains, entry->ref, 1);
/* entry is owned by the hash table here */
entry = NULL;
goto error;
}
entry->domains[entry->ref - 1] = g_strdup(name); entry->domains[entry->ref - 1] = g_strdup(name);
} }
} else { } else {

View File

@ -1070,17 +1070,11 @@ int virNetClientAddProgram(virNetClientPtr client,
{ {
virObjectLock(client); virObjectLock(client);
if (VIR_EXPAND_N(client->programs, client->nprograms, 1) < 0) VIR_EXPAND_N(client->programs, client->nprograms, 1);
goto error;
client->programs[client->nprograms-1] = virObjectRef(prog); client->programs[client->nprograms-1] = virObjectRef(prog);
virObjectUnlock(client); virObjectUnlock(client);
return 0; return 0;
error:
virObjectUnlock(client);
return -1;
} }
@ -1089,17 +1083,11 @@ int virNetClientAddStream(virNetClientPtr client,
{ {
virObjectLock(client); virObjectLock(client);
if (VIR_EXPAND_N(client->streams, client->nstreams, 1) < 0) VIR_EXPAND_N(client->streams, client->nstreams, 1);
goto error;
client->streams[client->nstreams-1] = virObjectRef(st); client->streams[client->nstreams-1] = virObjectRef(st);
virObjectUnlock(client); virObjectUnlock(client);
return 0; return 0;
error:
virObjectUnlock(client);
return -1;
} }

View File

@ -657,8 +657,7 @@ virNetDaemonAddSignalHandler(virNetDaemonPtr dmn,
if (virNetDaemonSignalSetup(dmn) < 0) if (virNetDaemonSignalSetup(dmn) < 0)
goto error; goto error;
if (VIR_EXPAND_N(dmn->signals, dmn->nsignals, 1) < 0) VIR_EXPAND_N(dmn->signals, dmn->nsignals, 1);
goto error;
sigdata = g_new0(virNetDaemonSignal, 1); sigdata = g_new0(virNetDaemonSignal, 1);

View File

@ -182,16 +182,10 @@ virNetLibsshSessionAuthMethodNew(virNetLibsshSessionPtr sess)
auth = g_new0(virNetLibsshAuthMethod, 1); auth = g_new0(virNetLibsshAuthMethod, 1);
if (VIR_EXPAND_N(sess->auths, sess->nauths, 1) < 0) VIR_EXPAND_N(sess->auths, sess->nauths, 1);
goto error;
sess->auths[sess->nauths - 1] = auth; sess->auths[sess->nauths - 1] = auth;
return auth; return auth;
error:
VIR_FREE(auth);
return NULL;
} }
/* string representation of public key of remote server */ /* string representation of public key of remote server */

View File

@ -290,8 +290,7 @@ int virNetServerAddClient(virNetServerPtr srv,
if (virNetServerClientInit(client) < 0) if (virNetServerClientInit(client) < 0)
goto error; goto error;
if (VIR_EXPAND_N(srv->clients, srv->nclients, 1) < 0) VIR_EXPAND_N(srv->clients, srv->nclients, 1);
goto error;
srv->clients[srv->nclients-1] = virObjectRef(client); srv->clients[srv->nclients-1] = virObjectRef(client);
virObjectLock(client); virObjectLock(client);
@ -620,9 +619,7 @@ int virNetServerAddService(virNetServerPtr srv,
{ {
virObjectLock(srv); virObjectLock(srv);
if (VIR_EXPAND_N(srv->services, srv->nservices, 1) < 0) VIR_EXPAND_N(srv->services, srv->nservices, 1);
goto error;
srv->services[srv->nservices-1] = virObjectRef(svc); srv->services[srv->nservices-1] = virObjectRef(svc);
virNetServerServiceSetDispatcher(svc, virNetServerServiceSetDispatcher(svc,
@ -631,10 +628,6 @@ int virNetServerAddService(virNetServerPtr srv,
virObjectUnlock(srv); virObjectUnlock(srv);
return 0; return 0;
error:
virObjectUnlock(srv);
return -1;
} }
@ -787,17 +780,11 @@ int virNetServerAddProgram(virNetServerPtr srv,
{ {
virObjectLock(srv); virObjectLock(srv);
if (VIR_EXPAND_N(srv->programs, srv->nprograms, 1) < 0) VIR_EXPAND_N(srv->programs, srv->nprograms, 1);
goto error;
srv->programs[srv->nprograms-1] = virObjectRef(prog); srv->programs[srv->nprograms-1] = virObjectRef(prog);
virObjectUnlock(srv); virObjectUnlock(srv);
return 0; return 0;
error:
virObjectUnlock(srv);
return -1;
} }
int virNetServerSetTLSContext(virNetServerPtr srv, int virNetServerSetTLSContext(virNetServerPtr srv,

View File

@ -440,8 +440,7 @@ int virNetSocketNewListenTCP(const char *nodename,
VIR_DEBUG("%p f=%d f=%d", &addr, runp->ai_family, addr.data.sa.sa_family); VIR_DEBUG("%p f=%d f=%d", &addr, runp->ai_family, addr.data.sa.sa_family);
if (VIR_EXPAND_N(socks, nsocks, 1) < 0) VIR_EXPAND_N(socks, nsocks, 1);
goto error;
if (!(socks[nsocks-1] = virNetSocketNew(&addr, NULL, false, fd, -1, 0, false))) if (!(socks[nsocks-1] = virNetSocketNew(&addr, NULL, false, fd, -1, 0, false)))
goto error; goto error;

View File

@ -175,16 +175,10 @@ virNetSSHSessionAuthMethodNew(virNetSSHSessionPtr sess)
auth = g_new0(virNetSSHAuthMethod, 1); auth = g_new0(virNetSSHAuthMethod, 1);
if (VIR_EXPAND_N(sess->auths, sess->nauths, 1) < 0) VIR_EXPAND_N(sess->auths, sess->nauths, 1);
goto error;
sess->auths[sess->nauths - 1] = auth; sess->auths[sess->nauths - 1] = auth;
return auth; return auth;
error:
VIR_FREE(auth);
return NULL;
} }
/* keyboard interactive authentication callback */ /* keyboard interactive authentication callback */

View File

@ -649,8 +649,7 @@ virStorageBackendRBDGetVolNames(virStorageBackendRBDStatePtr ptr)
name += strlen(name) + 1; name += strlen(name) + 1;
} }
if (VIR_EXPAND_N(names, nnames, 1) < 0) VIR_EXPAND_N(names, nnames, 1);
goto error;
return names; return names;

View File

@ -279,8 +279,7 @@ virStorageFileBackendGlusterReadlinkCallback(const char *path,
return 1; return 1;
realloc: realloc:
if (VIR_EXPAND_N(buf, bufsiz, 256) < 0) VIR_EXPAND_N(buf, bufsiz, 256);
return -1;
if ((ret = glfs_readlink(priv->vol, path, buf, bufsiz)) < 0) { if ((ret = glfs_readlink(priv->vol, path, buf, bufsiz)) < 0) {
virReportSystemError(errno, virReportSystemError(errno,

View File

@ -146,8 +146,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src,
size_t skip; size_t skip;
g_auto(GStrv) parts = NULL; g_auto(GStrv) parts = NULL;
if (VIR_EXPAND_N(src->hosts, src->nhosts, 1) < 0) VIR_EXPAND_N(src->hosts, src->nhosts, 1);
return -1;
if ((port = strchr(hostport, ']'))) { if ((port = strchr(hostport, ']'))) {
/* ipv6, strip brackets */ /* ipv6, strip brackets */

View File

@ -228,7 +228,7 @@ virCommandFDSet(virCommandPtr cmd,
if (virCommandFDIsSet(cmd, fd)) if (virCommandFDIsSet(cmd, fd))
return; return;
ignore_value(VIR_EXPAND_N(cmd->passfd, cmd->npassfd, 1)); VIR_EXPAND_N(cmd->passfd, cmd->npassfd, 1);
cmd->passfd[cmd->npassfd - 1].fd = fd; cmd->passfd[cmd->npassfd - 1].fd = fd;
cmd->passfd[cmd->npassfd - 1].flags = flags; cmd->passfd[cmd->npassfd - 1].flags = flags;

View File

@ -2010,7 +2010,6 @@ virFileGetMountSubtreeImpl(const char *mtabpath,
FILE *procmnt; FILE *procmnt;
struct mntent mntent; struct mntent mntent;
char mntbuf[1024]; char mntbuf[1024];
int ret = -1;
char **mounts = NULL; char **mounts = NULL;
size_t nmounts = 0; size_t nmounts = 0;
@ -2031,8 +2030,7 @@ virFileGetMountSubtreeImpl(const char *mtabpath,
mntent.mnt_dir[strlen(prefix)] == '/'))) mntent.mnt_dir[strlen(prefix)] == '/')))
continue; continue;
if (VIR_EXPAND_N(mounts, nmounts, nmounts ? 1 : 2) < 0) VIR_EXPAND_N(mounts, nmounts, nmounts ? 1 : 2);
goto cleanup;
mounts[nmounts - 2] = g_strdup(mntent.mnt_dir); mounts[nmounts - 2] = g_strdup(mntent.mnt_dir);
} }
@ -2042,13 +2040,8 @@ virFileGetMountSubtreeImpl(const char *mtabpath,
*mountsret = mounts; *mountsret = mounts;
*nmountsret = nmounts ? nmounts - 1 : 0; *nmountsret = nmounts ? nmounts - 1 : 0;
ret = 0;
cleanup:
if (ret < 0)
g_strfreev(mounts);
endmntent(procmnt); endmntent(procmnt);
return ret; return 0;
} }
#else /* ! defined WITH_MNTENT_H && defined WITH_GETMNTENT_R */ #else /* ! defined WITH_MNTENT_H && defined WITH_GETMNTENT_R */
static int static int
@ -3548,8 +3541,7 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
if (STRNEQ(mb.mnt_type, "hugetlbfs")) if (STRNEQ(mb.mnt_type, "hugetlbfs"))
continue; continue;
if (VIR_EXPAND_N(fs, nfs, 1) < 0) VIR_EXPAND_N(fs, nfs, 1);
goto cleanup;
tmp = &fs[nfs - 1]; tmp = &fs[nfs - 1];

View File

@ -510,8 +510,7 @@ void virFirewallStartTransaction(virFirewallPtr firewall,
group = virFirewallGroupNew(); group = virFirewallGroupNew();
group->actionFlags = flags; group->actionFlags = flags;
ignore_value(VIR_EXPAND_N(firewall->groups, VIR_EXPAND_N(firewall->groups, firewall->ngroups, 1);
firewall->ngroups, 1));
firewall->groups[firewall->ngroups - 1] = group; firewall->groups[firewall->ngroups - 1] = group;
firewall->currentGroup = firewall->ngroups - 1; firewall->currentGroup = firewall->ngroups - 1;
} }

View File

@ -214,9 +214,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace,
} }
res->lockHeld = true; res->lockHeld = true;
if (VIR_EXPAND_N(res->owners, res->nOwners, 1) < 0) VIR_EXPAND_N(res->owners, res->nOwners, 1);
goto error;
res->owners[res->nOwners-1] = owner; res->owners[res->nOwners-1] = owner;
return res; return res;
@ -583,8 +581,7 @@ int virLockSpaceAcquireResource(virLockSpacePtr lockspace,
if ((res->flags & VIR_LOCK_SPACE_ACQUIRE_SHARED) && if ((res->flags & VIR_LOCK_SPACE_ACQUIRE_SHARED) &&
(flags & VIR_LOCK_SPACE_ACQUIRE_SHARED)) { (flags & VIR_LOCK_SPACE_ACQUIRE_SHARED)) {
if (VIR_EXPAND_N(res->owners, res->nOwners, 1) < 0) VIR_EXPAND_N(res->owners, res->nOwners, 1);
goto cleanup;
res->owners[res->nOwners-1] = owner; res->owners[res->nOwners-1] = owner;
goto done; goto done;

View File

@ -653,7 +653,6 @@ int virProcessGetNamespaces(pid_t pid,
size_t *nfdlist, size_t *nfdlist,
int **fdlist) int **fdlist)
{ {
int ret = -1;
size_t i = 0; size_t i = 0;
const char *ns[] = { "user", "ipc", "uts", "net", "pid", "mnt" }; const char *ns[] = { "user", "ipc", "uts", "net", "pid", "mnt" };
@ -667,24 +666,12 @@ int virProcessGetNamespaces(pid_t pid,
nsfile = g_strdup_printf("/proc/%llu/ns/%s", (long long)pid, ns[i]); nsfile = g_strdup_printf("/proc/%llu/ns/%s", (long long)pid, ns[i]);
if ((fd = open(nsfile, O_RDONLY)) >= 0) { if ((fd = open(nsfile, O_RDONLY)) >= 0) {
if (VIR_EXPAND_N(*fdlist, *nfdlist, 1) < 0) { VIR_EXPAND_N(*fdlist, *nfdlist, 1);
VIR_FORCE_CLOSE(fd);
goto cleanup;
}
(*fdlist)[(*nfdlist)-1] = fd; (*fdlist)[(*nfdlist)-1] = fd;
} }
} }
ret = 0; return 0;
cleanup:
if (ret < 0) {
for (i = 0; i < *nfdlist; i++)
VIR_FORCE_CLOSE((*fdlist)[i]);
VIR_FREE(*fdlist);
}
return ret;
} }

View File

@ -608,10 +608,9 @@ virResctrlGetCacheInfo(virResctrlInfoPtr resctrl,
if (rv < 0) if (rv < 0)
goto cleanup; goto cleanup;
if (resctrl->nlevels <= level && if (resctrl->nlevels <= level)
VIR_EXPAND_N(resctrl->levels, resctrl->nlevels, VIR_EXPAND_N(resctrl->levels, resctrl->nlevels,
level - resctrl->nlevels + 1) < 0) level - resctrl->nlevels + 1);
goto cleanup;
if (!resctrl->levels[level]) { if (!resctrl->levels[level]) {
virResctrlInfoPerTypePtr *types = NULL; virResctrlInfoPerTypePtr *types = NULL;
@ -932,8 +931,7 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
i_type->max_cache_id++; i_type->max_cache_id++;
} }
if (VIR_EXPAND_N(*controls, *ncontrols, 1) < 0) VIR_EXPAND_N(*controls, *ncontrols, 1);
goto error;
(*controls)[*ncontrols - 1] = g_new0(virResctrlInfoPerCache, 1); (*controls)[*ncontrols - 1] = g_new0(virResctrlInfoPerCache, 1);
memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_type->control)); memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_type->control));
} }
@ -1098,9 +1096,8 @@ virResctrlAllocGetType(virResctrlAllocPtr alloc,
{ {
virResctrlAllocPerLevelPtr a_level = NULL; virResctrlAllocPerLevelPtr a_level = NULL;
if (alloc->nlevels <= level && if (alloc->nlevels <= level)
VIR_EXPAND_N(alloc->levels, alloc->nlevels, level - alloc->nlevels + 1) < 0) VIR_EXPAND_N(alloc->levels, alloc->nlevels, level - alloc->nlevels + 1);
return NULL;
if (!alloc->levels[level]) { if (!alloc->levels[level]) {
virResctrlAllocPerTypePtr *types = NULL; virResctrlAllocPerTypePtr *types = NULL;
@ -1132,10 +1129,9 @@ virResctrlAllocUpdateMask(virResctrlAllocPtr alloc,
if (!a_type) if (!a_type)
return -1; return -1;
if (a_type->nmasks <= cache && if (a_type->nmasks <= cache)
VIR_EXPAND_N(a_type->masks, a_type->nmasks, VIR_EXPAND_N(a_type->masks, a_type->nmasks,
cache - a_type->nmasks + 1) < 0) cache - a_type->nmasks + 1);
return -1;
if (!a_type->masks[cache]) if (!a_type->masks[cache])
a_type->masks[cache] = virBitmapNewCopy(mask); a_type->masks[cache] = virBitmapNewCopy(mask);
@ -1156,10 +1152,9 @@ virResctrlAllocUpdateSize(virResctrlAllocPtr alloc,
if (!a_type) if (!a_type)
return -1; return -1;
if (a_type->nsizes <= cache && if (a_type->nsizes <= cache)
VIR_EXPAND_N(a_type->sizes, a_type->nsizes, VIR_EXPAND_N(a_type->sizes, a_type->nsizes,
cache - a_type->nsizes + 1) < 0) cache - a_type->nsizes + 1);
return -1;
if (!a_type->sizes[cache]) if (!a_type->sizes[cache])
a_type->sizes[cache] = g_new0(unsigned long long, 1); a_type->sizes[cache] = g_new0(unsigned long long, 1);
@ -1316,10 +1311,9 @@ virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr alloc,
alloc->mem_bw = mem_bw; alloc->mem_bw = mem_bw;
} }
if (mem_bw->nbandwidths <= id && if (mem_bw->nbandwidths <= id)
VIR_EXPAND_N(mem_bw->bandwidths, mem_bw->nbandwidths, VIR_EXPAND_N(mem_bw->bandwidths, mem_bw->nbandwidths,
id - mem_bw->nbandwidths + 1) < 0) id - mem_bw->nbandwidths + 1);
return -1;
if (mem_bw->bandwidths[id]) { if (mem_bw->bandwidths[id]) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
@ -1469,9 +1463,9 @@ virResctrlAllocParseProcessMemoryBandwidth(virResctrlInfoPtr resctrl,
"memory bandwidth node '%u'"), id); "memory bandwidth node '%u'"), id);
return -1; return -1;
} }
if (alloc->mem_bw->nbandwidths <= id && if (alloc->mem_bw->nbandwidths <= id) {
VIR_EXPAND_N(alloc->mem_bw->bandwidths, alloc->mem_bw->nbandwidths, VIR_EXPAND_N(alloc->mem_bw->bandwidths, alloc->mem_bw->nbandwidths,
id - alloc->mem_bw->nbandwidths + 1) < 0) { id - alloc->mem_bw->nbandwidths + 1);
return -1; return -1;
} }
if (!alloc->mem_bw->bandwidths[id]) if (!alloc->mem_bw->bandwidths[id])
@ -1856,9 +1850,8 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info)
if (info->membw_info) { if (info->membw_info) {
ret->mem_bw = g_new0(virResctrlAllocMemBW, 1); ret->mem_bw = g_new0(virResctrlAllocMemBW, 1);
if (VIR_EXPAND_N(ret->mem_bw->bandwidths, ret->mem_bw->nbandwidths, VIR_EXPAND_N(ret->mem_bw->bandwidths, ret->mem_bw->nbandwidths,
info->membw_info->max_id + 1) < 0) info->membw_info->max_id + 1);
goto error;
for (i = 0; i < ret->mem_bw->nbandwidths; i++) { for (i = 0; i < ret->mem_bw->nbandwidths; i++) {
ret->mem_bw->bandwidths[i] = g_new0(unsigned int, 1); ret->mem_bw->bandwidths[i] = g_new0(unsigned int, 1);
@ -2146,10 +2139,9 @@ virResctrlAllocCopyMemBW(virResctrlAllocPtr dst,
dst_bw = dst->mem_bw; dst_bw = dst->mem_bw;
if (src_bw->nbandwidths > dst_bw->nbandwidths && if (src_bw->nbandwidths > dst_bw->nbandwidths)
VIR_EXPAND_N(dst_bw->bandwidths, dst_bw->nbandwidths, VIR_EXPAND_N(dst_bw->bandwidths, dst_bw->nbandwidths,
src_bw->nbandwidths - dst_bw->nbandwidths) < 0) src_bw->nbandwidths - dst_bw->nbandwidths);
return -1;
for (i = 0; i < src_bw->nbandwidths; i++) { for (i = 0; i < src_bw->nbandwidths; i++) {
if (dst_bw->bandwidths[i]) if (dst_bw->bandwidths[i])

View File

@ -691,8 +691,7 @@ virStringSearch(const char *str,
/* '*matches' must always be NULL terminated in every iteration /* '*matches' must always be NULL terminated in every iteration
* of the loop, so start by allocating 1 element * of the loop, so start by allocating 1 element
*/ */
if (VIR_EXPAND_N(*matches, nmatches, 1) < 0) VIR_EXPAND_N(*matches, nmatches, 1);
goto cleanup;
while ((nmatches - 1) < max_matches) { while ((nmatches - 1) < max_matches) {
g_autoptr(GMatchInfo) info = NULL; g_autoptr(GMatchInfo) info = NULL;
@ -702,8 +701,7 @@ virStringSearch(const char *str,
if (!g_regex_match(regex, str, 0, &info)) if (!g_regex_match(regex, str, 0, &info))
break; break;
if (VIR_EXPAND_N(*matches, nmatches, 1) < 0) VIR_EXPAND_N(*matches, nmatches, 1);
goto cleanup;
match = g_match_info_fetch(info, 1); match = g_match_info_fetch(info, 1);

View File

@ -276,8 +276,7 @@ virSysinfoParsePPCProcessor(const char *base, virSysinfoDefPtr ret)
eol = strchr(base, '\n'); eol = strchr(base, '\n');
cur = strchr(base, ':') + 1; cur = strchr(base, ':') + 1;
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) VIR_EXPAND_N(ret->processor, ret->nprocessor, 1);
return -1;
processor = &ret->processor[ret->nprocessor - 1]; processor = &ret->processor[ret->nprocessor - 1];
virSkipSpaces(&cur); virSkipSpaces(&cur);
@ -409,8 +408,7 @@ virSysinfoParseARMProcessor(const char *base, virSysinfoDefPtr ret)
eol = strchr(base, '\n'); eol = strchr(base, '\n');
cur = strchr(base, ':') + 1; cur = strchr(base, ':') + 1;
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) VIR_EXPAND_N(ret->processor, ret->nprocessor, 1);
goto error;
processor = &ret->processor[ret->nprocessor - 1]; processor = &ret->processor[ret->nprocessor - 1];
virSkipSpaces(&cur); virSkipSpaces(&cur);
@ -425,10 +423,6 @@ virSysinfoParseARMProcessor(const char *base, virSysinfoDefPtr ret)
VIR_FREE(processor_type); VIR_FREE(processor_type);
return 0; return 0;
error:
VIR_FREE(processor_type);
return -1;
} }
/* virSysinfoRead for ARMv7 /* virSysinfoRead for ARMv7
@ -544,8 +538,7 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
while ((tmp_base = strstr(tmp_base, "processor ")) while ((tmp_base = strstr(tmp_base, "processor "))
&& (tmp_base = virSysinfoParseS390Line(tmp_base, "processor ", && (tmp_base = virSysinfoParseS390Line(tmp_base, "processor ",
&procline))) { &procline))) {
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) VIR_EXPAND_N(ret->processor, ret->nprocessor, 1);
goto error;
processor = &ret->processor[ret->nprocessor - 1]; processor = &ret->processor[ret->nprocessor - 1];
processor->processor_manufacturer = g_strdup(manufacturer); processor->processor_manufacturer = g_strdup(manufacturer);
if (!virSysinfoParseS390Delimited(procline, "version", if (!virSysinfoParseS390Delimited(procline, "version",
@ -770,7 +763,6 @@ virSysinfoParseX86BaseBoard(const char *base,
virSysinfoBaseBoardDefPtr *baseBoard, virSysinfoBaseBoardDefPtr *baseBoard,
size_t *nbaseBoard) size_t *nbaseBoard)
{ {
int ret = -1;
const char *cur; const char *cur;
char *eol = NULL; char *eol = NULL;
virSysinfoBaseBoardDefPtr boards = NULL; virSysinfoBaseBoardDefPtr boards = NULL;
@ -779,8 +771,7 @@ virSysinfoParseX86BaseBoard(const char *base,
while (base && (cur = strstr(base, "Base Board Information"))) { while (base && (cur = strstr(base, "Base Board Information"))) {
virSysinfoBaseBoardDefPtr def; virSysinfoBaseBoardDefPtr def;
if (VIR_EXPAND_N(boards, nboards, 1) < 0) VIR_EXPAND_N(boards, nboards, 1);
goto cleanup;
def = &boards[nboards - 1]; def = &boards[nboards - 1];
@ -842,13 +833,7 @@ virSysinfoParseX86BaseBoard(const char *base,
*nbaseBoard = nboards; *nbaseBoard = nboards;
*baseBoard = g_steal_pointer(&boards); *baseBoard = g_steal_pointer(&boards);
nboards = 0; return 0;
ret = 0;
cleanup:
while (nboards--)
virSysinfoBaseBoardDefClear(&boards[nboards]);
VIR_FREE(boards);
return ret;
} }
@ -981,8 +966,7 @@ virSysinfoParseOEMStrings(const char *base,
if (!eol) if (!eol)
continue; continue;
if (VIR_EXPAND_N(strings->values, strings->nvalues, 1) < 0) VIR_EXPAND_N(strings->values, strings->nvalues, 1);
goto cleanup;
/* If OEM String contains newline, dmidecode escapes it as a dot. /* If OEM String contains newline, dmidecode escapes it as a dot.
* If this is the case then run dmidecode again to get raw string. * If this is the case then run dmidecode again to get raw string.
@ -1023,8 +1007,7 @@ virSysinfoParseX86Processor(const char *base, virSysinfoDefPtr ret)
base = tmp_base; base = tmp_base;
eol = NULL; eol = NULL;
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) VIR_EXPAND_N(ret->processor, ret->nprocessor, 1);
return -1;
processor = &ret->processor[ret->nprocessor - 1]; processor = &ret->processor[ret->nprocessor - 1];
if ((cur = strstr(base, "Socket Designation: ")) != NULL) { if ((cur = strstr(base, "Socket Designation: ")) != NULL) {
@ -1124,8 +1107,7 @@ virSysinfoParseX86Memory(const char *base, virSysinfoDefPtr ret)
base = tmp_base; base = tmp_base;
eol = NULL; eol = NULL;
if (VIR_EXPAND_N(ret->memory, ret->nmemory, 1) < 0) VIR_EXPAND_N(ret->memory, ret->nmemory, 1);
return -1;
memory = &ret->memory[ret->nmemory - 1]; memory = &ret->memory[ret->nmemory - 1];
if ((cur = strstr(base, "Size: ")) != NULL) { if ((cur = strstr(base, "Size: ")) != NULL) {

View File

@ -738,8 +738,7 @@ virSystemdActivationAddFD(virSystemdActivationPtr act,
return 0; return 0;
} }
if (VIR_EXPAND_N(ent->fds, ent->nfds, 1) < 0) VIR_EXPAND_N(ent->fds, ent->nfds, 1);
return -1;
VIR_DEBUG("Record extra FD %d with name %s", fd, name); VIR_DEBUG("Record extra FD %d with name %s", fd, name);
ent->fds[ent->nfds - 1] = fd; ent->fds[ent->nfds - 1] = fd;

View File

@ -183,8 +183,7 @@ virThreadPoolExpand(virThreadPoolPtr pool, size_t gain, bool priority)
size_t i = 0; size_t i = 0;
struct virThreadPoolWorkerData *data = NULL; struct virThreadPoolWorkerData *data = NULL;
if (VIR_EXPAND_N(*workers, *curWorkers, gain) < 0) VIR_EXPAND_N(*workers, *curWorkers, gain);
return -1;
for (i = 0; i < gain; i++) { for (i = 0; i < gain; i++) {
g_autofree char *name = NULL; g_autofree char *name = NULL;

View File

@ -328,8 +328,7 @@ virTypedParamsReplaceString(virTypedParameterPtr *params,
} }
old = param->value.s; old = param->value.s;
} else { } else {
if (VIR_EXPAND_N(*params, n, 1) < 0) VIR_EXPAND_N(*params, n, 1);
return -1;
param = *params + n - 1; param = *params + n - 1;
} }

View File

@ -472,8 +472,7 @@ virVBoxSnapshotConfAllChildren(virVBoxSnapshotConfHardDiskPtr disk,
for (i = 0; i < disk->nchildren; i++) { for (i = 0; i < disk->nchildren; i++) {
tempSize = virVBoxSnapshotConfAllChildren(disk->children[i], &tempList); tempSize = virVBoxSnapshotConfAllChildren(disk->children[i], &tempList);
if (VIR_EXPAND_N(ret, returnSize, tempSize) < 0) VIR_EXPAND_N(ret, returnSize, tempSize);
goto error;
for (j = 0; j < tempSize; j++) for (j = 0; j < tempSize; j++)
ret[returnSize - tempSize + j] = tempList[j]; ret[returnSize - tempSize + j] = tempList[j];
@ -481,17 +480,10 @@ virVBoxSnapshotConfAllChildren(virVBoxSnapshotConfHardDiskPtr disk,
VIR_FREE(tempList); VIR_FREE(tempList);
} }
if (VIR_EXPAND_N(ret, returnSize, 1) < 0) VIR_EXPAND_N(ret, returnSize, 1);
goto error;
ret[returnSize - 1] = disk; ret[returnSize - 1] = disk;
*list = ret; *list = ret;
return returnSize; return returnSize;
error:
VIR_FREE(tempList);
VIR_FREE(ret);
return 0;
} }
void void
@ -785,9 +777,7 @@ virVBoxSnapshotConfAddSnapshotToXmlMachine(virVBoxSnapshotConfSnapshotPtr snapsh
_("Unable to find the snapshot %s"), snapshotParentName); _("Unable to find the snapshot %s"), snapshotParentName);
return -1; return -1;
} }
if (VIR_EXPAND_N(parentSnapshot->children, parentSnapshot->nchildren, 1) < 0) VIR_EXPAND_N(parentSnapshot->children, parentSnapshot->nchildren, 1);
return -1;
parentSnapshot->children[parentSnapshot->nchildren - 1] = snapshot; parentSnapshot->children[parentSnapshot->nchildren - 1] = snapshot;
} }
@ -829,9 +819,7 @@ virVBoxSnapshotConfAddHardDiskToMediaRegistry(virVBoxSnapshotConfHardDiskPtr har
return -1; return -1;
} }
/* Hard disk found */ /* Hard disk found */
if (VIR_EXPAND_N(parentDisk->children, parentDisk->nchildren, 1) < 0) VIR_EXPAND_N(parentDisk->children, parentDisk->nchildren, 1);
return -1;
parentDisk->children[parentDisk->nchildren - 1] = hardDisk; parentDisk->children[parentDisk->nchildren - 1] = hardDisk;
if (hardDisk->parent == NULL) if (hardDisk->parent == NULL)
hardDisk->parent = parentDisk; hardDisk->parent = parentDisk;
@ -1395,8 +1383,7 @@ virVBoxSnapshotConfDiskListToOpen(virVBoxSnapshotConfMachinePtr machine,
ret[returnSize - 1] = hardDisk; ret[returnSize - 1] = hardDisk;
while (hardDisk->parent != NULL) { while (hardDisk->parent != NULL) {
if (VIR_EXPAND_N(ret, returnSize, 1) < 0) VIR_EXPAND_N(ret, returnSize, 1);
return 0;
ret[returnSize - 1] = hardDisk->parent; ret[returnSize - 1] = hardDisk->parent;
hardDisk = hardDisk->parent; hardDisk = hardDisk->parent;
} }
@ -1424,8 +1411,7 @@ virVBoxSnapshotConfRemoveFakeDisks(virVBoxSnapshotConfMachinePtr machine)
for (i = 0; i < machine->mediaRegistry->ndisks; i++) { for (i = 0; i < machine->mediaRegistry->ndisks; i++) {
tempSize = virVBoxSnapshotConfAllChildren(machine->mediaRegistry->disks[i], &tempList); tempSize = virVBoxSnapshotConfAllChildren(machine->mediaRegistry->disks[i], &tempList);
if (VIR_EXPAND_N(diskList, diskSize, tempSize) < 0) VIR_EXPAND_N(diskList, diskSize, tempSize);
goto cleanup;
for (j = 0; j < tempSize; j++) for (j = 0; j < tempSize; j++)
diskList[diskSize - tempSize + j] = tempList[j]; diskList[diskSize - tempSize + j] = tempList[j];
@ -1475,8 +1461,7 @@ virVBoxSnapshotConfDiskIsInMediaRegistry(virVBoxSnapshotConfMachinePtr machine,
for (i = 0; i < machine->mediaRegistry->ndisks; i++) { for (i = 0; i < machine->mediaRegistry->ndisks; i++) {
tempSize = virVBoxSnapshotConfAllChildren(machine->mediaRegistry->disks[i], &tempList); tempSize = virVBoxSnapshotConfAllChildren(machine->mediaRegistry->disks[i], &tempList);
if (VIR_EXPAND_N(diskList, diskSize, tempSize) < 0) VIR_EXPAND_N(diskList, diskSize, tempSize);
goto cleanup;
for (j = 0; j < tempSize; j++) for (j = 0; j < tempSize; j++)
diskList[diskSize - tempSize + j] = tempList[j]; diskList[diskSize - tempSize + j] = tempList[j];

View File

@ -68,8 +68,7 @@ testCompareXMLToXMLFiles(const char *inxml,
if (flags & TEST_VDA_BITMAP) { if (flags & TEST_VDA_BITMAP) {
virDomainCheckpointDiskDefPtr disk; virDomainCheckpointDiskDefPtr disk;
if (VIR_EXPAND_N(def->disks, def->ndisks, 1) < 0) VIR_EXPAND_N(def->disks, def->ndisks, 1);
return -1;
disk = &def->disks[0]; disk = &def->disks[0];
if (disk->bitmap) if (disk->bitmap)
return -1; return -1;

View File

@ -117,8 +117,7 @@ qemuMonitorTestAddResponse(qemuMonitorTestPtr test,
if (have < want) { if (have < want) {
size_t need = want - have; size_t need = want - have;
if (VIR_EXPAND_N(test->outgoing, test->outgoingCapacity, need) < 0) VIR_EXPAND_N(test->outgoing, test->outgoingCapacity, need);
return -1;
} }
want -= 2; want -= 2;
@ -283,10 +282,7 @@ qemuMonitorTestIO(virNetSocketPtr sock,
char *t1, *t2; char *t1, *t2;
if ((test->incomingCapacity - test->incomingLength) < 1024) { if ((test->incomingCapacity - test->incomingLength) < 1024) {
if (VIR_EXPAND_N(test->incoming, test->incomingCapacity, 1024) < 0) { VIR_EXPAND_N(test->incoming, test->incomingCapacity, 1024);
err = true;
goto cleanup;
}
} }
if ((ret = virNetSocketRead(sock, if ((ret = virNetSocketRead(sock,
@ -868,9 +864,7 @@ qemuMonitorTestAddItemParams(qemuMonitorTestPtr test,
} }
i = data->nargs; i = data->nargs;
if (VIR_EXPAND_N(data->args, data->nargs, 1)) VIR_EXPAND_N(data->args, data->nargs, 1);
goto error;
data->args[i].argname = g_strdup(argname); data->args[i].argname = g_strdup(argname);
data->args[i].argval = g_strdup(argval); data->args[i].argval = g_strdup(argval);
} }

View File

@ -144,12 +144,7 @@ testSELinuxLoadFileList(const char *testname,
*tmp = '\0'; *tmp = '\0';
} }
if (VIR_EXPAND_N(*files, *nfiles, 1) < 0) { VIR_EXPAND_N(*files, *nfiles, 1);
VIR_FREE(file);
VIR_FREE(context);
goto cleanup;
}
(*files)[(*nfiles)-1].file = file; (*files)[(*nfiles)-1].file = file;
(*files)[(*nfiles)-1].context = context; (*files)[(*nfiles)-1].context = context;
} }

View File

@ -133,8 +133,7 @@ testExpandArray(const void *opaque G_GNUC_UNUSED)
t[i].b = 20; t[i].b = 20;
} }
if (VIR_EXPAND_N(t, nt, 5) < 0) VIR_EXPAND_N(t, nt, 5);
goto cleanup;
if (testCheckNonNull(t) < 0) if (testCheckNonNull(t) < 0)
goto cleanup; goto cleanup;

View File

@ -4068,10 +4068,7 @@ cmdStartGetFDs(vshControl *ctl,
vshError(ctl, _("Unable to parse FD number '%s'"), fdlist[i]); vshError(ctl, _("Unable to parse FD number '%s'"), fdlist[i]);
goto error; goto error;
} }
if (VIR_EXPAND_N(fds, nfds, 1) < 0) { VIR_EXPAND_N(fds, nfds, 1);
vshError(ctl, "%s", _("Unable to allocate FD list"));
goto error;
}
fds[nfds - 1] = fd; fds[nfds - 1] = fd;
} }
@ -10055,16 +10052,10 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd)
setlabel = false; setlabel = false;
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
if (VIR_EXPAND_N(cmdargv, ncmdargv, 1) < 0) { VIR_EXPAND_N(cmdargv, ncmdargv, 1);
vshError(ctl, _("%s: %d: failed to allocate argv"),
__FILE__, __LINE__);
}
cmdargv[ncmdargv-1] = opt->data; cmdargv[ncmdargv-1] = opt->data;
} }
if (VIR_EXPAND_N(cmdargv, ncmdargv, 1) < 0) { VIR_EXPAND_N(cmdargv, ncmdargv, 1);
vshError(ctl, _("%s: %d: failed to allocate argv"),
__FILE__, __LINE__);
}
cmdargv[ncmdargv - 1] = NULL; cmdargv[ncmdargv - 1] = NULL;
if ((nfdlist = virDomainLxcOpenNamespace(dom, &fdlist, 0)) < 0) if ((nfdlist = virDomainLxcOpenNamespace(dom, &fdlist, 0)) < 0)
@ -13956,11 +13947,7 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd)
return false; return false;
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
if (VIR_EXPAND_N(mountpoints, nmountpoints, 1) < 0) { VIR_EXPAND_N(mountpoints, nmountpoints, 1);
vshError(ctl, _("%s: %d: failed to allocate mountpoints"),
__FILE__, __LINE__);
goto cleanup;
}
mountpoints[nmountpoints-1] = opt->data; mountpoints[nmountpoints-1] = opt->data;
} }
@ -14009,11 +13996,7 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd)
return false; return false;
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
if (VIR_EXPAND_N(mountpoints, nmountpoints, 1) < 0) { VIR_EXPAND_N(mountpoints, nmountpoints, 1);
vshError(ctl, _("%s: %d: failed to allocate mountpoints"),
__FILE__, __LINE__);
goto cleanup;
}
mountpoints[nmountpoints-1] = opt->data; mountpoints[nmountpoints-1] = opt->data;
} }