--- src/conf/cpu_conf.c | 34 +--- src/conf/domain_conf.c | 328 +++++++++++------------------------ src/conf/domain_event.c | 30 +--- src/conf/interface_conf.c | 35 +--- src/conf/netdev_bandwidth_conf.c | 12 +- src/conf/netdev_vlan_conf.c | 4 +- src/conf/netdev_vport_profile_conf.c | 4 +- src/conf/network_conf.c | 86 +++------ src/conf/node_device_conf.c | 29 +--- src/conf/nwfilter_conf.c | 33 +--- src/conf/nwfilter_ipaddrmap.c | 8 +- src/conf/nwfilter_params.c | 35 +--- src/conf/secret_conf.c | 4 +- src/conf/snapshot_conf.c | 47 ++--- src/conf/storage_conf.c | 38 +--- src/conf/storage_encryption_conf.c | 12 +- src/conf/virchrdev.c | 12 +- 17 files changed, 200 insertions(+), 551 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 960d8a6..16e2d52 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -103,7 +103,7 @@ virCPUDefCopyModel(virCPUDefPtr dst, VIR_STRDUP(dst->vendor, src->vendor) < 0 || VIR_STRDUP(dst->vendor_id, src->vendor_id) < 0 || VIR_ALLOC_N(dst->features, src->nfeatures) < 0) - goto no_memory; + return -1; dst->nfeatures_max = dst->nfeatures = src->nfeatures; for (i = 0; i < dst->nfeatures; i++) { @@ -123,10 +123,6 @@ virCPUDefCopyModel(virCPUDefPtr dst, } return 0; - -no_memory: - virReportOOMError(); - return -1; } virCPUDefPtr @@ -135,12 +131,9 @@ virCPUDefCopy(const virCPUDefPtr cpu) virCPUDefPtr copy; unsigned int i; - if (!cpu) + if (!cpu || VIR_ALLOC(copy) < 0) return NULL; - if (VIR_ALLOC(copy) < 0) - goto no_memory; - copy->type = cpu->type; copy->mode = cpu->mode; copy->match = cpu->match; @@ -155,7 +148,7 @@ virCPUDefCopy(const virCPUDefPtr cpu) if (cpu->ncells) { if (VIR_ALLOC_N(copy->cells, cpu->ncells) < 0) - goto no_memory; + goto error; copy->ncells_max = copy->ncells = cpu->ncells; for (i = 0; i < cpu->ncells; i++) { @@ -165,7 +158,7 @@ virCPUDefCopy(const virCPUDefPtr cpu) copy->cells[i].cpumask = virBitmapNewCopy(cpu->cells[i].cpumask); if (!copy->cells[i].cpumask) - goto no_memory; + goto error; if (VIR_STRDUP(copy->cells[i].cpustr, cpu->cells[i].cpustr) < 0) goto error; @@ -175,8 +168,6 @@ virCPUDefCopy(const virCPUDefPtr cpu) return copy; -no_memory: - virReportOOMError(); error: virCPUDefFree(copy); return NULL; @@ -202,10 +193,8 @@ virCPUDefParseXML(const xmlNodePtr node, return NULL; } - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (mode == VIR_CPU_TYPE_AUTO) { if (virXPathBoolean("boolean(./arch)", ctxt)) { @@ -383,7 +372,7 @@ virCPUDefParseXML(const xmlNodePtr node, if (VIR_RESIZE_N(def->features, def->nfeatures_max, def->nfeatures, n) < 0) - goto no_memory; + goto error; def->nfeatures = n; } @@ -443,7 +432,7 @@ virCPUDefParseXML(const xmlNodePtr node, if (VIR_RESIZE_N(def->cells, def->ncells_max, def->ncells, n) < 0) - goto no_memory; + goto error; def->ncells = n; @@ -490,9 +479,6 @@ cleanup: VIR_FREE(nodes); return def; -no_memory: - virReportOOMError(); - error: virCPUDefFree(def); def = NULL; @@ -689,7 +675,7 @@ virCPUDefAddFeature(virCPUDefPtr def, if (VIR_RESIZE_N(def->features, def->nfeatures_max, def->nfeatures, 1) < 0) - goto no_memory; + return -1; if (def->type == VIR_CPU_TYPE_HOST) policy = -1; @@ -701,10 +687,6 @@ virCPUDefAddFeature(virCPUDefPtr def, def->nfeatures++; return 0; - -no_memory: - virReportOOMError(); - return -1; } bool diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 921a4f6..d45c770 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1603,15 +1603,9 @@ virDomainHostdevDefPtr virDomainHostdevDefAlloc(void) { virDomainHostdevDefPtr def = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); - return NULL; - } - if (VIR_ALLOC(def->info) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0 || + VIR_ALLOC(def->info) < 0) VIR_FREE(def); - return NULL; - } return def; } @@ -1793,21 +1787,20 @@ virDomainVcpuPinDefCopy(virDomainVcpuPinDefPtr *src, int nvcpupin) int i = 0; virDomainVcpuPinDefPtr *ret = NULL; - if (VIR_ALLOC_N(ret, nvcpupin) < 0) { - goto no_memory; - } + if (VIR_ALLOC_N(ret, nvcpupin) < 0) + goto error; for (i = 0; i < nvcpupin; i++) { if (VIR_ALLOC(ret[i]) < 0) - goto no_memory; + goto error; ret[i]->vcpuid = src[i]->vcpuid; if ((ret[i]->cpumask = virBitmapNewCopy(src[i]->cpumask)) == NULL) - goto no_memory; + goto error; } return ret; -no_memory: +error: if (ret) { for (; i >= 0; --i) { if (ret[i]) { @@ -1817,7 +1810,6 @@ no_memory: } VIR_FREE(ret); } - virReportOOMError(); return NULL; } @@ -2031,10 +2023,8 @@ virDomainObjNew(virDomainXMLOptionPtr xmlopt) return NULL; if (xmlopt->privateData.alloc) { - if (!(domain->privateData = (xmlopt->privateData.alloc)())) { - virReportOOMError(); + if (!(domain->privateData = (xmlopt->privateData.alloc)())) goto error; - } domain->privateDataFreeFunc = xmlopt->privateData.free; } @@ -2060,10 +2050,8 @@ virDomainDefPtr virDomainDefNew(const char *name, { virDomainDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (VIR_STRDUP(def->name, name) < 0) { VIR_FREE(def); @@ -2664,7 +2652,7 @@ virDomainDefRejectDuplicateControllers(virDomainDefPtr def) for (i = 0; i < VIR_DOMAIN_CONTROLLER_TYPE_LAST; i++) { if (max_idx[i] >= 0 && !(bitmaps[i] = virBitmapNew(max_idx[i] + 1))) - goto no_memory; + goto cleanup; nbitmaps++; } @@ -2690,10 +2678,6 @@ cleanup: for (i = 0; i < nbitmaps; i++) virBitmapFree(bitmaps[i]); return ret; - -no_memory: - virReportOOMError(); - goto cleanup; } @@ -2769,7 +2753,7 @@ virDomainDefPostParseInternal(virDomainDefPtr def, if (!def->consoles[0]) { /* allocate a new console type for the stolen one */ if (VIR_ALLOC(def->consoles[0]) < 0) - goto no_memory; + return -1; /* Create an console alias for the serial port */ def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE; @@ -2780,10 +2764,6 @@ virDomainDefPostParseInternal(virDomainDefPtr def, if (virDomainDefRejectDuplicateControllers(def) < 0) return -1; return 0; - -no_memory: - virReportOOMError(); - return -1; } @@ -4257,10 +4237,8 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, char *p; virSecurityLabelDefPtr def = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto error; - } p = virXPathStringLimit("string(./@type)", VIR_SECURITY_LABEL_BUFLEN-1, ctxt); @@ -4381,10 +4359,8 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, if (n == 0) return 0; - if (VIR_ALLOC_N(def->seclabels, n) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->seclabels, n) < 0) goto error; - } /* Parse each "seclabel" tag */ for (i = 0; i < n; i++) { @@ -4467,16 +4443,12 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn, if (n == 0) return 0; - if (VIR_ALLOC_N(seclabels, n) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(seclabels, n) < 0) goto error; - } nseclabels = n; for (i = 0; i < n; i++) { - if (VIR_ALLOC(seclabels[i]) < 0) { - virReportOOMError(); + if (VIR_ALLOC(seclabels[i]) < 0) goto error; - } } for (i = 0; i < n; i++) { @@ -4561,10 +4533,8 @@ virDomainLeaseDefParseXML(xmlNodePtr node) char *path = NULL; char *offset = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } cur = node->children; while (cur != NULL) { @@ -4642,10 +4612,8 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node, goto cleanup; } - if (VIR_ALLOC(def->srcpool) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->srcpool) < 0) goto cleanup; - } def->srcpool->pool = pool; pool = NULL; @@ -4722,10 +4690,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, int expected_secret_usage = -1; int auth_secret_usage = -1; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } def->geometry.cylinders = 0; def->geometry.heads = 0; @@ -4800,10 +4766,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, while (child != NULL) { if (child->type == XML_ELEMENT_NODE && xmlStrEqual(child->name, BAD_CAST "host")) { - if (VIR_REALLOC_N(hosts, nhosts + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(hosts, nhosts + 1) < 0) goto error; - } hosts[nhosts].name = NULL; hosts[nhosts].port = NULL; hosts[nhosts].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; @@ -5186,10 +5150,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, if (def->srcpool) { char *tmp; if (virAsprintf(&tmp, "pool = '%s', volume = '%s'", - def->srcpool->pool, def->srcpool->volume) < 0) { - virReportOOMError(); + def->srcpool->pool, def->srcpool->volume) < 0) goto error; - } virReportError(VIR_ERR_NO_TARGET, "%s", tmp); VIR_FREE(tmp); @@ -5577,10 +5539,8 @@ virDomainControllerDefParseXML(xmlNodePtr node, char *model = NULL; char *queues = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); if (type) { @@ -5750,10 +5710,8 @@ virDomainParseScaledValue(const char *xpath, unsigned long long bytes; *val = 0; - if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0) { - virReportOOMError(); + if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0) goto cleanup; - } ret = virXPathULongLong(xpath_full, ctxt, &bytes); if (ret < 0) { if (ret == -2) @@ -5770,10 +5728,8 @@ virDomainParseScaledValue(const char *xpath, } VIR_FREE(xpath_full); - if (virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0) { - virReportOOMError(); + if (virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0) goto cleanup; - } unit = virXPathString(xpath_full, ctxt); if (virScaleInteger(&bytes, unit, scale, max) < 0) @@ -5809,10 +5765,8 @@ virDomainFSDefParseXML(xmlNodePtr node, ctxt->node = node; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); if (type) { @@ -5984,10 +5938,8 @@ virDomainActualNetDefParseXML(xmlNodePtr node, char *mode = NULL; char *addrtype = NULL; - if (VIR_ALLOC(actual) < 0) { - virReportOOMError(); + if (VIR_ALLOC(actual) < 0) return -1; - } ctxt->node = node; @@ -6148,10 +6100,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr oldnode = ctxt->node; int ret; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } ctxt->node = node; @@ -6703,10 +6653,8 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def, addrStr = virXMLPropString(cur, "address"); portStr = virXMLPropString(cur, "port"); - if (VIR_ALLOC(def->target.addr) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->target.addr) < 0) goto error; - } if (addrStr == NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -7002,10 +6950,8 @@ virDomainChrDefPtr virDomainChrDefNew(void) { virDomainChrDefPtr def = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } def->target.port = -1; return def; @@ -7147,10 +7093,8 @@ virDomainSmartcardDefParseXML(xmlNodePtr node, virDomainSmartcardDefPtr def; int i; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } mode = virXMLPropString(node, "mode"); if (mode == NULL) { @@ -7291,10 +7235,8 @@ virDomainTPMDefParseXML(const xmlNodePtr node, xmlNodePtr *backends = NULL; int nbackends; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } model = virXMLPropString(node, "model"); if (model != NULL && @@ -7377,10 +7319,8 @@ virDomainInputDefParseXML(const char *ostype, char *type = NULL; char *bus = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); bus = virXMLPropString(node, "bus"); @@ -7473,10 +7413,8 @@ virDomainHubDefParseXML(xmlNodePtr node, unsigned int flags) virDomainHubDefPtr def; char *type = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); @@ -7523,10 +7461,8 @@ virDomainTimerDefParseXML(const xmlNodePtr node, xmlNodePtr catchup; int ret; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } ctxt->node = node; @@ -7796,10 +7732,8 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, char *listenAddr = NULL; xmlNodePtr save = ctxt->node; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } ctxt->node = node; @@ -7829,10 +7763,8 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, if (nListens > 0) { int ii; - if (VIR_ALLOC_N(def->listens, nListens) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->listens, nListens) < 0) goto error; - } for (ii = 0; ii < nListens; ii++) { int ret = virDomainGraphicsListenDefParseXML(&def->listens[ii], @@ -8320,10 +8252,8 @@ virDomainSoundCodecDefParseXML(const xmlNodePtr node) char *type; virDomainSoundCodecDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); if ((def->type = virDomainSoundCodecTypeFromString(type)) < 0) { @@ -8353,10 +8283,8 @@ virDomainSoundDefParseXML(const xmlNodePtr node, virDomainSoundDefPtr def; xmlNodePtr save = ctxt->node; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } ctxt->node = node; @@ -8380,7 +8308,6 @@ virDomainSoundDefParseXML(const xmlNodePtr node, int ii; if (VIR_ALLOC_N(def->codecs, ncodecs) < 0) { - virReportOOMError(); VIR_FREE(codecNodes); goto error; } @@ -8422,10 +8349,8 @@ virDomainWatchdogDefParseXML(const xmlNodePtr node, char *action = NULL; virDomainWatchdogDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } model = virXMLPropString(node, "model"); if (model == NULL) { @@ -8481,10 +8406,8 @@ virDomainRNGDefParseXML(const xmlNodePtr node, xmlNodePtr *backends = NULL; int nbackends; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (!(model = virXMLPropString(node, "model"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing RNG device model")); @@ -8552,10 +8475,8 @@ virDomainRNGDefParseXML(const xmlNodePtr node, goto error; } - if (VIR_ALLOC(def->source.chardev) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->source.chardev) < 0) goto error; - } def->source.chardev->type = virDomainChrTypeFromString(type); if (def->source.chardev->type < 0) { @@ -8600,10 +8521,8 @@ virDomainMemballoonDefParseXML(const xmlNodePtr node, char *model; virDomainMemballoonDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } model = virXMLPropString(node, "model"); if (model == NULL) { @@ -8637,10 +8556,8 @@ virDomainNVRAMDefParseXML(const xmlNodePtr node, { virDomainNVRAMDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0) goto error; @@ -8668,10 +8585,8 @@ virSysinfoParseXML(const xmlNodePtr node, return NULL; } - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } type = virXMLPropString(node, "type"); if (type == NULL) { @@ -8853,10 +8768,8 @@ virDomainVideoAccelDefParseXML(const xmlNodePtr node) { if (!support3d && !support2d) return NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (support3d) { if (STREQ(support3d, "yes")) @@ -8890,10 +8803,8 @@ virDomainVideoDefParseXML(const xmlNodePtr node, char *ram = NULL; char *primary = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } cur = node->children; while (cur != NULL) { @@ -9087,10 +8998,8 @@ virDomainRedirdevDefParseXML(const xmlNodePtr node, char *bus, *type = NULL; int remaining; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } bus = virXMLPropString(node, "bus"); if (bus) { @@ -9224,10 +9133,8 @@ virDomainRedirFilterUsbDevDefParseXML(const xmlNodePtr node) char *version = NULL, *allow = NULL; virDomainRedirFilterUsbDevDefPtr def; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } class = virXMLPropString(node, "class"); if (class) { @@ -9320,7 +9227,7 @@ virDomainRedirFilterDefParseXML(const xmlNodePtr node, virDomainRedirFilterDefPtr def = NULL; if (VIR_ALLOC(def) < 0) - goto no_memory; + goto error; ctxt->node = node; if ((n = virXPathNodeSet("./usbdev", ctxt, &nodes)) < 0) { @@ -9328,7 +9235,7 @@ virDomainRedirFilterDefParseXML(const xmlNodePtr node, } if (n && VIR_ALLOC_N(def->usbdevs, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainRedirFilterUsbDevDefPtr usbdev = @@ -9343,9 +9250,6 @@ virDomainRedirFilterDefParseXML(const xmlNodePtr node, ctxt->node = save; return def; -no_memory: - virReportOOMError(); - error: VIR_FREE(nodes); virDomainRedirFilterDefFree(def); @@ -9415,10 +9319,8 @@ virDomainDeviceDefParse(const char *xmlStr, node = ctxt->node; - if (VIR_ALLOC(dev) < 0) { - virReportOOMError(); + if (VIR_ALLOC(dev) < 0) goto error; - } if (xmlStrEqual(node->name, BAD_CAST "disk")) { dev->type = VIR_DOMAIN_DEVICE_DISK; @@ -10047,11 +9949,7 @@ int virDomainLeaseIndex(virDomainDefPtr def, int virDomainLeaseInsertPreAlloc(virDomainDefPtr def) { - if (VIR_EXPAND_N(def->leases, def->nleases, 1) < 0) { - virReportOOMError(); - return -1; - } - return 0; + return VIR_EXPAND_N(def->leases, def->nleases, 1); } int virDomainLeaseInsert(virDomainDefPtr def, @@ -10275,10 +10173,8 @@ virDomainIdmapDefParseXML(xmlXPathContextPtr ctxt, virDomainIdMapEntryPtr idmap = NULL; xmlNodePtr save_ctxt = ctxt->node; - if (VIR_ALLOC_N(idmap, num) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(idmap, num) < 0) goto cleanup; - } for (i = 0; i < num; i++) { ctxt->node = node[i]; @@ -10332,10 +10228,8 @@ virDomainVcpuPinDefParseXML(const xmlNodePtr node, char *tmp = NULL; int ret; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } ctxt->node = node; @@ -10421,10 +10315,8 @@ virDomainDefMaybeAddController(virDomainDefPtr def, return 0; } - if (VIR_ALLOC(cont) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cont) < 0) return -1; - } cont->type = type; cont->idx = idx; @@ -10483,10 +10375,8 @@ virDomainResourceDefParse(xmlNodePtr node, ctxt->node = node; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto error; - } /* Find out what type of virtualization to use */ if (!(def->partition = virXPathString("string(./partition)", ctxt))) { @@ -10552,10 +10442,8 @@ virDomainDefParseXML(xmlDocPtr xml, bool usb_master = false; bool primaryVideo = false; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (!(flags & VIR_DOMAIN_XML_INACTIVE)) if (virXPathLong("string(./@id)", ctxt, &id) < 0) @@ -10715,7 +10603,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->blkio.devices, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { int j; @@ -10894,7 +10782,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->cputune.vcpupin, n) < 0) - goto no_memory; + goto error; if (n > def->maxvcpus) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -10934,10 +10822,8 @@ virDomainDefParseXML(xmlDocPtr xml, * the policy specified explicitly as def->cpuset. */ if (def->cpumask) { - if (VIR_REALLOC_N(def->cputune.vcpupin, def->vcpus) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(def->cputune.vcpupin, def->vcpus) < 0) goto error; - } for (i = 0; i < def->vcpus; i++) { if (virDomainVcpuPinIsDuplicate(def->cputune.vcpupin, @@ -10947,10 +10833,8 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainVcpuPinDefPtr vcpupin = NULL; - if (VIR_ALLOC(vcpupin) < 0) { - virReportOOMError(); + if (VIR_ALLOC(vcpupin) < 0) goto error; - } vcpupin->cpumask = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN); virBitmapCopy(vcpupin->cpumask, def->cpumask); @@ -11360,7 +11244,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->clock.timers, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainTimerDefPtr timer = virDomainTimerDefParseXML(nodes[i], @@ -11471,7 +11355,7 @@ virDomainDefParseXML(xmlDocPtr xml, } if (VIR_ALLOC_N(def->os.initargv, n+1) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { if (!nodes[i]->children || !nodes[i]->children->content) { @@ -11512,7 +11396,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->disks, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainDiskDefPtr disk = virDomainDiskDefParseXML(xmlopt, @@ -11534,7 +11418,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->controllers, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainControllerDefPtr controller = virDomainControllerDefParseXML(nodes[i], @@ -11591,7 +11475,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->leases, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainLeaseDefPtr lease = virDomainLeaseDefParseXML(nodes[i]); if (!lease) @@ -11606,7 +11490,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->fss, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainFSDefPtr fs = virDomainFSDefParseXML(nodes[i], ctxt, flags); @@ -11622,7 +11506,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->nets, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainNetDefPtr net = virDomainNetDefParseXML(xmlopt, nodes[i], @@ -11637,7 +11521,7 @@ virDomainDefParseXML(xmlDocPtr xml, /* <interface type='hostdev'> must also be in the hostdevs array */ if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV && virDomainHostdevInsert(def, &net->data.hostdev.def) < 0) { - goto no_memory; + goto error; } } VIR_FREE(nodes); @@ -11648,7 +11532,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->smartcards, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainSmartcardDefPtr card = virDomainSmartcardDefParseXML(nodes[i], @@ -11666,7 +11550,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->parallels, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt, @@ -11694,7 +11578,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->serials, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt, @@ -11724,7 +11608,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->consoles, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt, @@ -11744,7 +11628,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->channels, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt, @@ -11785,7 +11669,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->inputs, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainInputDefPtr input = virDomainInputDefParseXML(def->os.type, @@ -11825,7 +11709,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->graphics, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainGraphicsDefPtr graphics = virDomainGraphicsDefParseXML(nodes[i], ctxt, @@ -11842,7 +11726,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) { - goto no_memory; + goto error; } if (STREQ(def->os.type, "hvm")) { input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; @@ -11854,7 +11738,7 @@ virDomainDefParseXML(xmlDocPtr xml, if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) { virDomainInputDefFree(input); - goto no_memory; + goto error; } def->inputs[def->ninputs] = input; def->ninputs++; @@ -11866,7 +11750,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->sounds, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainSoundDefPtr sound = virDomainSoundDefParseXML(nodes[i], ctxt, @@ -11883,7 +11767,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->videos, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { size_t ii = def->nvideos; virDomainVideoDefPtr video = virDomainVideoDefParseXML(nodes[i], @@ -11918,7 +11802,7 @@ virDomainDefParseXML(xmlDocPtr xml, if (def->ngraphics && !def->nvideos) { virDomainVideoDefPtr video; if (VIR_ALLOC(video) < 0) - goto no_memory; + goto error; video->type = virDomainVideoDefaultType(def); if (video->type < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -11930,7 +11814,7 @@ virDomainDefParseXML(xmlDocPtr xml, video->heads = 1; if (VIR_ALLOC_N(def->videos, 1) < 0) { virDomainVideoDefFree(video); - goto no_memory; + goto error; } def->videos[def->nvideos++] = video; } @@ -11940,7 +11824,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_REALLOC_N(def->hostdevs, def->nhostdevs + n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainHostdevDefPtr hostdev; @@ -12009,7 +11893,7 @@ virDomainDefParseXML(xmlDocPtr xml, def->virtType == VIR_DOMAIN_VIRT_KVM) { virDomainMemballoonDefPtr memballoon; if (VIR_ALLOC(memballoon) < 0) - goto no_memory; + goto error; memballoon->model = def->virtType == VIR_DOMAIN_VIRT_XEN ? VIR_DOMAIN_MEMBALLOON_MODEL_XEN : VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO; @@ -12072,7 +11956,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->hubs, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainHubDefPtr hub = virDomainHubDefParseXML(nodes[i], flags); if (!hub) @@ -12095,7 +11979,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } if (n && VIR_ALLOC_N(def->redirdevs, n) < 0) - goto no_memory; + goto error; for (i = 0; i < n; i++) { virDomainRedirdevDefPtr redirdev = virDomainRedirdevDefParseXML(nodes[i], bootHash, @@ -12240,8 +12124,6 @@ virDomainDefParseXML(xmlDocPtr xml, return def; -no_memory: - virReportOOMError(); error: VIR_FREE(tmp); VIR_FREE(nodes); @@ -13692,10 +13574,8 @@ virDomainVcpuPinAdd(virDomainVcpuPinDefPtr **vcpupin_list, vcpupin->vcpuid = vcpu; virBitmapFree(vcpupin->cpumask); vcpupin->cpumask = virBitmapNewData(cpumap, maplen); - if (!vcpupin->cpumask) { - virReportOOMError(); + if (!vcpupin->cpumask) return -1; - } return 0; } @@ -13703,22 +13583,21 @@ virDomainVcpuPinAdd(virDomainVcpuPinDefPtr **vcpupin_list, /* No existing vcpupin matches vcpu, adding a new one */ if (VIR_ALLOC(vcpupin) < 0) - goto no_memory; + goto error; vcpupin->vcpuid = vcpu; vcpupin->cpumask = virBitmapNewData(cpumap, maplen); if (!vcpupin->cpumask) - goto no_memory; + goto error; if (VIR_REALLOC_N(*vcpupin_list, *nvcpupin + 1) < 0) - goto no_memory; + goto error; (*vcpupin_list)[(*nvcpupin)++] = vcpupin; return 0; -no_memory: - virReportOOMError(); +error: virDomainVcpuPinDefFree(vcpupin); return -1; } @@ -13753,10 +13632,8 @@ virDomainVcpuPinDel(virDomainDefPtr def, int vcpu) if (--def->cputune.nvcpupin == 0) { VIR_FREE(def->cputune.vcpupin); } else { - if (VIR_REALLOC_N(def->cputune.vcpupin, def->cputune.nvcpupin) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(def->cputune.vcpupin, def->cputune.nvcpupin) < 0) return -1; - } } return 0; @@ -13771,10 +13648,8 @@ virDomainEmulatorPinAdd(virDomainDefPtr def, if (!def->cputune.emulatorpin) { /* No emulatorpin exists yet. */ - if (VIR_ALLOC(emulatorpin) < 0) { - virReportOOMError(); + if (VIR_ALLOC(emulatorpin) < 0) return -1; - } emulatorpin->vcpuid = -1; emulatorpin->cpumask = virBitmapNewData(cpumap, maplen); @@ -17063,9 +16938,7 @@ char { char *ret; - if (virAsprintf(&ret, "%s/%s.xml", dir, name) < 0) - virReportOOMError(); - + ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name)); return ret; } @@ -17690,9 +17563,7 @@ virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t ii, bool force0) def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { if (!def->listens && (ii == 0) && force0) { - if (VIR_ALLOC(def->listens) < 0) - virReportOOMError(); - else + if (VIR_ALLOC(def->listens) >= 0) def->nListens = 1; } @@ -18082,12 +17953,9 @@ virDomainObjListExport(virDomainObjListPtr doms, }; virObjectLock(doms); - if (domains) { - if (VIR_ALLOC_N(data.domains, virHashSize(doms->objs) + 1) < 0) { - virReportOOMError(); - goto cleanup; - } - } + if (domains && + VIR_ALLOC_N(data.domains, virHashSize(doms->objs) + 1) < 0) + goto cleanup; virHashForEach(doms->objs, virDomainListPopulate, &data); @@ -18171,7 +18039,6 @@ virDomainDefGenSecurityLabelDef(const char *model) if (VIR_ALLOC(seclabel) < 0 || VIR_STRDUP(seclabel->model, model) < 0) { - virReportOOMError(); virSecurityLabelDefFree(seclabel); seclabel = NULL; } @@ -18186,7 +18053,6 @@ virDomainDiskDefGenSecurityLabelDef(const char *model) if (VIR_ALLOC(seclabel) < 0 || VIR_STRDUP(seclabel->model, model) < 0) { - virReportOOMError(); virSecurityDeviceLabelDefFree(seclabel); seclabel = NULL; } diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index bc43c28..260e554 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -376,7 +376,7 @@ virDomainEventCallbackListAddID(virConnectPtr conn, } /* Allocate new event */ if (VIR_ALLOC(event) < 0) - goto no_memory; + goto error; event->conn = conn; event->cb = callback; event->eventID = eventID; @@ -385,7 +385,7 @@ virDomainEventCallbackListAddID(virConnectPtr conn, if (dom) { if (VIR_ALLOC(event->dom) < 0) - goto no_memory; + goto error; if (VIR_STRDUP(event->dom->name, dom->name) < 0) goto error; memcpy(event->dom->uuid, dom->uuid, VIR_UUID_BUFLEN); @@ -394,7 +394,7 @@ virDomainEventCallbackListAddID(virConnectPtr conn, /* Make space on list */ if (VIR_REALLOC_N(cbList->callbacks, cbList->count + 1) < 0) - goto no_memory; + goto error; virObjectRef(event->conn); @@ -415,8 +415,6 @@ virDomainEventCallbackListAddID(virConnectPtr conn, return ret; -no_memory: - virReportOOMError(); error: if (event) { if (event->dom) @@ -566,11 +564,7 @@ virDomainEventQueueNew(void) { virDomainEventQueuePtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(VIR_ALLOC(ret)); return ret; } @@ -627,10 +621,8 @@ virDomainEventStateNew(void) { virDomainEventStatePtr state = NULL; - if (VIR_ALLOC(state) < 0) { - virReportOOMError(); + if (VIR_ALLOC(state) < 0) goto error; - } if (virMutexInit(&state->lock) < 0) { virReportSystemError(errno, "%s", @@ -639,10 +631,8 @@ virDomainEventStateNew(void) goto error; } - if (VIR_ALLOC(state->callbacks) < 0) { - virReportOOMError(); + if (VIR_ALLOC(state->callbacks) < 0) goto error; - } if (!(state->queue = virDomainEventQueueNew())) goto error; @@ -663,10 +653,8 @@ static virDomainEventPtr virDomainEventNewInternal(int eventID, { virDomainEventPtr event; - if (VIR_ALLOC(event) < 0) { - virReportOOMError(); + if (VIR_ALLOC(event) < 0) return NULL; - } event->eventID = eventID; if (VIR_STRDUP(event->dom.name, name) < 0) { @@ -1188,10 +1176,8 @@ virDomainEventQueuePush(virDomainEventQueuePtr evtQueue, /* Make space on queue */ if (VIR_REALLOC_N(evtQueue->events, - evtQueue->count + 1) < 0) { - virReportOOMError(); + evtQueue->count + 1) < 0) return -1; - } evtQueue->events[evtQueue->count] = event; evtQueue->count++; diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index 025a454..7725b39 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -318,20 +318,16 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def, if (ipNodes == NULL) return 0; - if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) goto error; - } def->nips = 0; for (ii = 0; ii < nIpNodes; ii++) { virInterfaceIpDefPtr ip; - if (VIR_ALLOC(ip) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ip) < 0) goto error; - } ctxt->node = ipNodes[ii]; ret = virInterfaceDefParseIp(ip, ctxt); @@ -377,20 +373,16 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDefPtr def, if (ipNodes == NULL) return 0; - if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) goto error; - } def->nips = 0; for (ii = 0; ii < nIpNodes; ii++) { virInterfaceIpDefPtr ip; - if (VIR_ALLOC(ip) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ip) < 0) goto error; - } ctxt->node = ipNodes[ii]; ret = virInterfaceDefParseIp(ip, ctxt); @@ -427,20 +419,16 @@ virInterfaceDefParseIfAdressing(virInterfaceDefPtr def, return 0; } - if (VIR_ALLOC_N(def->protos, nProtoNodes) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->protos, nProtoNodes) < 0) goto error; - } def->nprotos = 0; for (pp = 0; pp < nProtoNodes; pp++) { virInterfaceProtocolDefPtr proto; - if (VIR_ALLOC(proto) < 0) { - virReportOOMError(); + if (VIR_ALLOC(proto) < 0) goto error; - } ctxt->node = protoNodes[pp]; tmp = virXPathString("string(./@family)", ctxt); @@ -498,7 +486,6 @@ virInterfaceDefParseBridge(virInterfaceDefPtr def, } if (nbItf > 0) { if (VIR_ALLOC_N(def->data.bridge.itf, nbItf) < 0) { - virReportOOMError(); ret = -1; goto error; } @@ -545,7 +532,6 @@ virInterfaceDefParseBondItfs(virInterfaceDefPtr def, } if (VIR_ALLOC_N(def->data.bond.itf, nbItf) < 0) { - virReportOOMError(); ret = -1; goto error; } @@ -682,10 +668,8 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType) { } VIR_FREE(tmp); - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (((parentIfType == VIR_INTERFACE_TYPE_BOND) && (type != VIR_INTERFACE_TYPE_ETHERNET)) @@ -1266,10 +1250,8 @@ virInterfaceObjPtr virInterfaceAssignDef(virInterfaceObjListPtr interfaces, return iface; } - if (VIR_ALLOC(iface) < 0) { - virReportOOMError(); + if (VIR_ALLOC(iface) < 0) return NULL; - } if (virMutexInit(&iface->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); @@ -1280,7 +1262,6 @@ virInterfaceObjPtr virInterfaceAssignDef(virInterfaceObjListPtr interfaces, iface->def = def; if (VIR_REALLOC_N(interfaces->objs, interfaces->count + 1) < 0) { - virReportOOMError(); VIR_FREE(iface); return NULL; } diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_conf.c index 87249cb..da14909 100644 --- a/src/conf/netdev_bandwidth_conf.c +++ b/src/conf/netdev_bandwidth_conf.c @@ -120,10 +120,8 @@ virNetDevBandwidthParse(xmlNodePtr node, xmlNodePtr cur; xmlNodePtr in = NULL, out = NULL; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } if (!node || !xmlStrEqual(node->name, BAD_CAST "bandwidth")) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -158,10 +156,8 @@ virNetDevBandwidthParse(xmlNodePtr node, } if (in) { - if (VIR_ALLOC(def->in) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->in) < 0) goto error; - } if (virNetDevBandwidthParseRate(in, def->in) < 0) { /* helper reported error for us */ @@ -184,10 +180,8 @@ virNetDevBandwidthParse(xmlNodePtr node, } if (out) { - if (VIR_ALLOC(def->out) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def->out) < 0) goto error; - } if (virNetDevBandwidthParseRate(out, def->out) < 0) { /* helper reported error for us */ diff --git a/src/conf/netdev_vlan_conf.c b/src/conf/netdev_vlan_conf.c index 880a7ce..54fb0fd 100644 --- a/src/conf/netdev_vlan_conf.c +++ b/src/conf/netdev_vlan_conf.c @@ -54,10 +54,8 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de goto cleanup; } - if (VIR_ALLOC_N(def->tag, nTags) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->tag, nTags) < 0) goto cleanup; - } def->nativeMode = 0; def->nativeTag = 0; diff --git a/src/conf/netdev_vport_profile_conf.c b/src/conf/netdev_vport_profile_conf.c index c275339..e8199e2 100644 --- a/src/conf/netdev_vport_profile_conf.c +++ b/src/conf/netdev_vport_profile_conf.c @@ -50,10 +50,8 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags) virNetDevVPortProfilePtr virtPort = NULL; xmlNodePtr cur = node->children; - if (VIR_ALLOC(virtPort) < 0) { - virReportOOMError(); + if (VIR_ALLOC(virtPort) < 0) return NULL; - } if ((virtPortType = virXMLPropString(node, "type")) && (virtPort->virtPortType = virNetDevVPortTypeFromString(virtPortType)) <= 0) { diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index d6799d2..2ca120b 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -344,15 +344,11 @@ virNetworkAssignDef(virNetworkObjListPtr nets, return network; } - if (VIR_REALLOC_N(nets->objs, nets->count + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(nets->objs, nets->count + 1) < 0) return NULL; - } - if (VIR_ALLOC(network) < 0) { - virReportOOMError(); + if (VIR_ALLOC(network) < 0) return NULL; - } if (virMutexInit(&network->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); @@ -362,10 +358,8 @@ virNetworkAssignDef(virNetworkObjListPtr nets, virNetworkObjLock(network); network->def = def; - if (!(network->class_id = virBitmapNew(CLASS_ID_BITMAP_SIZE))) { - virReportOOMError(); + if (!(network->class_id = virBitmapNew(CLASS_ID_BITMAP_SIZE))) goto error; - } /* The first three class IDs are already taken */ ignore_value(virBitmapSetBit(network->class_id, 0)); @@ -796,10 +790,8 @@ virNetworkDHCPDefParseXML(const char *networkName, if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "range")) { - if (VIR_REALLOC_N(def->ranges, def->nranges + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(def->ranges, def->nranges + 1) < 0) return -1; - } if (virSocketAddrRangeParseXML(networkName, cur, &def->ranges[def->nranges]) < 0) { return -1; @@ -809,10 +801,8 @@ virNetworkDHCPDefParseXML(const char *networkName, } else if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "host")) { - if (VIR_REALLOC_N(def->hosts, def->nhosts + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(def->hosts, def->nhosts + 1) < 0) return -1; - } if (virNetworkDHCPHostDefParseXML(networkName, def, cur, &def->hosts[def->nhosts], false) < 0) { @@ -883,10 +873,8 @@ virNetworkDNSHostDefParseXML(const char *networkName, if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "hostname")) { if (cur->children != NULL) { - if (VIR_REALLOC_N(def->names, def->nnames + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(def->names, def->nnames + 1) < 0) goto error; - } def->names[def->nnames++] = (char *)xmlNodeGetContent(cur); if (!def->names[def->nnames - 1]) { virReportError(VIR_ERR_XML_DETAIL, @@ -1062,10 +1050,8 @@ virNetworkDNSDefParseXML(const char *networkName, goto cleanup; } if (nhosts > 0) { - if (VIR_ALLOC_N(def->hosts, nhosts) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->hosts, nhosts) < 0) goto cleanup; - } for (ii = 0; ii < nhosts; ii++) { if (virNetworkDNSHostDefParseXML(networkName, hostNodes[ii], @@ -1084,10 +1070,8 @@ virNetworkDNSDefParseXML(const char *networkName, goto cleanup; } if (nsrvs > 0) { - if (VIR_ALLOC_N(def->srvs, nsrvs) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->srvs, nsrvs) < 0) goto cleanup; - } for (ii = 0; ii < nsrvs; ii++) { if (virNetworkDNSSrvDefParseXML(networkName, srvNodes[ii], ctxt, @@ -1106,10 +1090,8 @@ virNetworkDNSDefParseXML(const char *networkName, goto cleanup; } if (ntxts > 0) { - if (VIR_ALLOC_N(def->txts, ntxts) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->txts, ntxts) < 0) goto cleanup; - } for (ii = 0; ii < ntxts; ii++) { if (virNetworkDNSTxtDefParseXML(networkName, txtNodes[ii], @@ -1786,11 +1768,8 @@ virNetworkForwardDefParseXML(const char *networkName, } if (nForwardIfs > 0 || forwardDev) { - - if (VIR_ALLOC_N(def->ifs, MAX(nForwardIfs, 1)) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->ifs, MAX(nForwardIfs, 1)) < 0) goto cleanup; - } if (forwardDev) { def->ifs[0].device.dev = forwardDev; @@ -1833,11 +1812,8 @@ virNetworkForwardDefParseXML(const char *networkName, } } else if (nForwardAddrs > 0) { - - if (VIR_ALLOC_N(def->ifs, nForwardAddrs) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->ifs, nForwardAddrs) < 0) goto cleanup; - } for (ii = 0; ii < nForwardAddrs; ii++) { if (!(type = virXMLPropString(forwardAddrNodes[ii], "type"))) { @@ -1880,11 +1856,8 @@ virNetworkForwardDefParseXML(const char *networkName, networkName); goto cleanup; } else if (nForwardPfs == 1) { - - if (VIR_ALLOC_N(def->pfs, nForwardPfs) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->pfs, nForwardPfs) < 0) goto cleanup; - } forwardDev = virXMLPropString(*forwardPfNodes, "dev"); if (!forwardDev) { @@ -1898,7 +1871,6 @@ virNetworkForwardDefParseXML(const char *networkName, def->pfs->dev = forwardDev; forwardDev = NULL; def->npfs++; - } ret = 0; @@ -1933,10 +1905,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) xmlNodePtr bandwidthNode = NULL; xmlNodePtr vlanNode; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } /* Extract network name */ def->name = virXPathString("string(./name[1])", ctxt); @@ -2040,10 +2010,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) int ii; /* allocate array to hold all the portgroups */ - if (VIR_ALLOC_N(def->portGroups, nPortGroups) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->portGroups, nPortGroups) < 0) goto error; - } /* parse each portgroup */ for (ii = 0; ii < nPortGroups; ii++) { int ret = virNetworkPortGroupParseXML(&def->portGroups[ii], @@ -2063,10 +2031,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) int ii; /* allocate array to hold all the addrs */ - if (VIR_ALLOC_N(def->ips, nIps) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->ips, nIps) < 0) goto error; - } /* parse each addr */ for (ii = 0; ii < nIps; ii++) { int ret = virNetworkIPDefParseXML(def->name, ipNodes[ii], @@ -2086,10 +2052,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) int ii; /* allocate array to hold all the route definitions */ - if (VIR_ALLOC_N(def->routes, nRoutes) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(def->routes, nRoutes) < 0) goto error; - } /* parse each definition */ for (ii = 0; ii < nRoutes; ii++) { int ret = virNetworkRouteDefParseXML(def->name, routeNodes[ii], @@ -3121,11 +3085,7 @@ char *virNetworkConfigFile(const char *dir, { char *ret = NULL; - if (virAsprintf(&ret, "%s/%s.xml", dir, name) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name)); return ret; } @@ -3159,10 +3119,8 @@ char *virNetworkAllocateBridge(const virNetworkObjListPtr nets, template = "virbr%d"; do { - if (virAsprintf(&newname, template, id) < 0) { - virReportOOMError(); + if (virAsprintf(&newname, template, id) < 0) return NULL; - } if (!virNetworkBridgeInUse(nets, newname, NULL)) { return newname; } @@ -4281,12 +4239,8 @@ virNetworkObjListExport(virConnectPtr conn, int ret = -1; int i; - if (nets) { - if (VIR_ALLOC_N(tmp_nets, netobjs.count + 1) < 0) { - virReportOOMError(); - goto cleanup; - } - } + if (nets && VIR_ALLOC_N(tmp_nets, netobjs.count + 1) < 0) + goto cleanup; for (i = 0; i < netobjs.count; i++) { virNetworkObjPtr netobj = netobjs.objs[i]; diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 7406652..6f97dc0 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -176,10 +176,8 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, return device; } - if (VIR_ALLOC(device) < 0) { - virReportOOMError(); + if (VIR_ALLOC(device) < 0) return NULL; - } if (virMutexInit(&device->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -194,7 +192,6 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, device->def = NULL; virNodeDeviceObjUnlock(device); virNodeDeviceObjFree(device); - virReportOOMError(); return NULL; } devs->objs[devs->count++] = device; @@ -1015,20 +1012,16 @@ virNodeDevCapPciDevIommuGroupParseXML(xmlXPathContextPtr ctxt, virDevicePCIAddress addr = { 0, 0, 0, 0, 0 }; if (virDevicePCIAddressParseXML(addrNodes[ii], &addr) < 0) goto cleanup; - if (VIR_ALLOC(pciAddr) < 0) { - virReportOOMError(); + if (VIR_ALLOC(pciAddr) < 0) goto cleanup; - } pciAddr->domain = addr.domain; pciAddr->bus = addr.bus; pciAddr->slot = addr.slot; pciAddr->function = addr.function; if (VIR_APPEND_ELEMENT(data->pci_dev.iommuGroupDevices, data->pci_dev.nIommuGroupDevices, - pciAddr, false) < 0) { - virReportOOMError(); + pciAddr, true) < 0) goto cleanup; - } } ret = 0; @@ -1159,10 +1152,8 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, char *tmp; int val, ret; - if (VIR_ALLOC(caps) < 0) { - virReportOOMError(); + if (VIR_ALLOC(caps) < 0) return NULL; - } tmp = virXMLPropString(node, "type"); if (!tmp) { @@ -1238,10 +1229,8 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, xmlNodePtr *nodes; int n, i; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) return NULL; - } /* Extract device name */ if (create == EXISTING_DEVICE) { @@ -1606,12 +1595,8 @@ virNodeDeviceObjListExport(virConnectPtr conn, int ret = -1; int i; - if (devices) { - if (VIR_ALLOC_N(tmp_devices, devobjs.count + 1) < 0) { - virReportOOMError(); - goto cleanup; - } - } + if (devices && VIR_ALLOC_N(tmp_devices, devobjs.count + 1) < 0) + goto cleanup; for (i = 0; i < devobjs.count; i++) { virNodeDeviceObjPtr devobj = devobjs.objs[i]; diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index b2be99a..664701d 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -378,7 +378,6 @@ virNWFilterRuleDefAddVar(virNWFilterRuleDefPtr nwf, } if (VIR_EXPAND_N(nwf->varAccess, nwf->nVarAccess, 1) < 0) { - virReportOOMError(); virNWFilterVarAccessFree(varAccess); return -1; } @@ -395,10 +394,8 @@ virNWFilterRuleDefAddString(virNWFilterRuleDefPtr nwf, const char *string, size_t maxstrlen) { - if (VIR_REALLOC_N(nwf->strings, nwf->nstrings+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(nwf->strings, nwf->nstrings+1) < 0) return NULL; - } if (VIR_STRNDUP(nwf->strings[nwf->nstrings], string, maxstrlen) < 0) return NULL; @@ -2039,10 +2036,8 @@ virNWFilterIncludeParse(xmlNodePtr cur) { virNWFilterIncludeDefPtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->filterref = virXMLPropString(cur, "filter"); if (!ret->filterref) { @@ -2303,10 +2298,8 @@ virNWFilterRuleParse(xmlNodePtr node) xmlNodePtr cur; virNWFilterRuleDefPtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } action = virXMLPropString(node, "action"); direction = virXMLPropString(node, "direction"); @@ -2499,10 +2492,8 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) { int chain_priority; const char *name_prefix; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->name = virXPathString("string(./@name)", ctxt); if (!ret->name) { @@ -2577,10 +2568,8 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) { while (curr != NULL) { if (curr->type == XML_ELEMENT_NODE) { - if (VIR_ALLOC(entry) < 0) { - virReportOOMError(); + if (VIR_ALLOC(entry) < 0) goto cleanup; - } /* ignore malformed rule and include elements */ if (xmlStrEqual(curr->name, BAD_CAST "rule")) @@ -2591,7 +2580,6 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) { if (entry->rule || entry->include) { if (VIR_REALLOC_N(ret->filterEntries, ret->nentries+1) < 0) { VIR_FREE(entry); - virReportOOMError(); goto cleanup; } ret->filterEntries[ret->nentries++] = entry; @@ -3032,10 +3020,8 @@ virNWFilterObjAssignDef(virConnectPtr conn, virNWFilterUnlockFilterUpdates(); - if (VIR_ALLOC(nwfilter) < 0) { - virReportOOMError(); + if (VIR_ALLOC(nwfilter) < 0) return NULL; - } if (virMutexInitRecursive(&nwfilter->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3051,7 +3037,6 @@ virNWFilterObjAssignDef(virConnectPtr conn, nwfilter->def = NULL; virNWFilterObjUnlock(nwfilter); virNWFilterObjFree(nwfilter); - virReportOOMError(); return NULL; } nwfilters->objs[nwfilters->count++] = nwfilter; @@ -3485,11 +3470,7 @@ char *virNWFilterConfigFile(const char *dir, { char *ret = NULL; - if (virAsprintf(&ret, "%s/%s.xml", dir, name) < 0) { - virReportOOMError(); - return NULL; - } - + ignore_value(virAsprintf(&ret, "%s/%s.xml", dir, name)); return ret; } diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c index 317069d..b592a90 100644 --- a/src/conf/nwfilter_ipaddrmap.c +++ b/src/conf/nwfilter_ipaddrmap.c @@ -58,10 +58,8 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr) val = virHashLookup(ipAddressMap->hashTable, ifname); if (!val) { val = virNWFilterVarValueCreateSimple(addr); - if (!val) { - virReportOOMError(); + if (!val) goto cleanup; - } ret = virNWFilterHashTablePut(ipAddressMap, ifname, val, 1); goto cleanup; } else { @@ -146,10 +144,8 @@ int virNWFilterIPAddrMapInit(void) { ipAddressMap = virNWFilterHashTableCreate(0); - if (!ipAddressMap) { - virReportOOMError(); + if (!ipAddressMap) return -1; - } if (virMutexInit(&ipAddressMapLock) < 0) { virNWFilterIPAddrMapShutdown(); diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index 48b89b7..84ddbfa 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -71,10 +71,8 @@ virNWFilterVarValueCopy(const virNWFilterVarValuePtr val) unsigned i; char *str; - if (VIR_ALLOC(res) < 0) { - virReportOOMError(); + if (VIR_ALLOC(res) < 0) return NULL; - } res->valType = val->valType; switch (res->valType) { @@ -99,7 +97,6 @@ virNWFilterVarValueCopy(const virNWFilterVarValuePtr val) return res; err_exit: - virReportOOMError(); virNWFilterVarValueFree(res); return NULL; } @@ -115,10 +112,8 @@ virNWFilterVarValueCreateSimple(char *value) return NULL; } - if (VIR_ALLOC(val) < 0) { - virReportOOMError(); + if (VIR_ALLOC(val) < 0) return NULL; - } val->valType = NWFILTER_VALUE_TYPE_SIMPLE; val->u.simple.value = value; @@ -227,7 +222,6 @@ virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value) tmp = val->u.simple.value; if (VIR_ALLOC_N(val->u.array.values, 2) < 0) { val->u.simple.value = tmp; - virReportOOMError(); return -1; } val->valType = NWFILTER_VALUE_TYPE_ARRAY; @@ -239,10 +233,8 @@ virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value) case NWFILTER_VALUE_TYPE_ARRAY: if (VIR_EXPAND_N(val->u.array.values, - val->u.array.nValues, 1) < 0) { - virReportOOMError(); + val->u.array.nValues, 1) < 0) return -1; - } val->u.array.values[val->u.array.nValues - 1] = value; rc = 0; break; @@ -383,10 +375,8 @@ virNWFilterVarCombIterAddVariable(virNWFilterVarCombIterEntryPtr cie, } } - if (VIR_EXPAND_N(cie->varNames, cie->nVarNames, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(cie->varNames, cie->nVarNames, 1) < 0) return -1; - } cie->varNames[cie->nVarNames - 1] = varName; @@ -477,10 +467,8 @@ virNWFilterVarCombIterCreate(virNWFilterHashTablePtr hash, int iterIndex = -1; unsigned int nextIntIterId = VIR_NWFILTER_MAX_ITERID + 1; - if (VIR_ALLOC_VAR(res, virNWFilterVarCombIterEntry, 1 + nVarAccess) < 0) { - virReportOOMError(); + if (VIR_ALLOC_VAR(res, virNWFilterVarCombIterEntry, 1 + nVarAccess) < 0) return NULL; - } res->hashTable = hash; @@ -703,10 +691,8 @@ virNWFilterHashTablePtr virNWFilterHashTableCreate(int n) { virNWFilterHashTablePtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->hashTable = virHashCreate(n, hashDataFree); if (!ret->hashTable) { VIR_FREE(ret); @@ -754,7 +740,6 @@ addToTable(void *payload, const void *name, void *data) val = virNWFilterVarValueCopy((virNWFilterVarValuePtr)payload); if (!val) { - virReportOOMError(); atts->errOccurred = 1; return; } @@ -836,10 +821,8 @@ virNWFilterParseParamAttributes(xmlNodePtr cur) virNWFilterVarValuePtr value; virNWFilterHashTablePtr table = virNWFilterHashTableCreate(0); - if (!table) { - virReportOOMError(); + if (!table) return NULL; - } cur = cur->children; @@ -989,10 +972,8 @@ virNWFilterVarAccessParse(const char *varAccess) virNWFilterVarAccessPtr dest; const char *input = varAccess; - if (VIR_ALLOC(dest) < 0) { - virReportOOMError(); + if (VIR_ALLOC(dest) < 0) return NULL; - } idx = strspn(input, VALID_VARNAME); diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index 5bcfe12..335884e 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -152,10 +152,8 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) } ctxt->node = root; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } prop = virXPathString("string(./@ephemeral)", ctxt); if (prop != NULL) { diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index b500111..4610737 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -195,10 +195,8 @@ virDomainSnapshotDefParseString(const char *xmlStr, } xmlKeepBlanksDefault(keepBlanksDefault); - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } if (!xmlStrEqual(ctxt->node->name, BAD_CAST "domainsnapshot")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("domainsnapshot")); @@ -214,10 +212,8 @@ virDomainSnapshotDefParseString(const char *xmlStr, _("a redefined snapshot must have a name")); goto cleanup; } - if (virAsprintf(&def->name, "%lld", (long long)tv.tv_sec) < 0) { - virReportOOMError(); + if (virAsprintf(&def->name, "%lld", (long long)tv.tv_sec) < 0) goto cleanup; - } } def->description = virXPathString("string(./description)", ctxt); @@ -321,10 +317,8 @@ virDomainSnapshotDefParseString(const char *xmlStr, goto cleanup; if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_DISKS) { def->ndisks = i; - if (def->ndisks && VIR_ALLOC_N(def->disks, def->ndisks) < 0) { - virReportOOMError(); + if (def->ndisks && VIR_ALLOC_N(def->disks, def->ndisks) < 0) goto cleanup; - } for (i = 0; i < def->ndisks; i++) { if (virDomainSnapshotDiskDefParseXML(nodes[i], &def->disks[i]) < 0) goto cleanup; @@ -407,10 +401,8 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, goto cleanup; } - if (!(map = virBitmapNew(def->dom->ndisks))) { - virReportOOMError(); + if (!(map = virBitmapNew(def->dom->ndisks))) goto cleanup; - } /* Double check requested disks. */ for (i = 0; i < def->ndisks; i++) { @@ -471,10 +463,8 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, /* Provide defaults for all remaining disks. */ ndisks = def->ndisks; if (VIR_EXPAND_N(def->disks, def->ndisks, - def->dom->ndisks - def->ndisks) < 0) { - virReportOOMError(); + def->dom->ndisks - def->ndisks) < 0) goto cleanup; - } for (i = 0; i < def->dom->ndisks; i++) { virDomainSnapshotDiskDefPtr disk; @@ -522,21 +512,18 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, tmp = strrchr(original, '.'); if (!tmp || strchr(tmp, '/')) { - ignore_value(virAsprintf(&disk->file, "%s.%s", - original, def->name)); + if (virAsprintf(&disk->file, "%s.%s", original, def->name) < 0) + goto cleanup; } else { if ((tmp - original) > INT_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("integer overflow")); goto cleanup; } - ignore_value(virAsprintf(&disk->file, "%.*s.%s", - (int) (tmp - original), original, - def->name)); - } - if (!disk->file) { - virReportOOMError(); - goto cleanup; + if (virAsprintf(&disk->file, "%.*s.%s", + (int) (tmp - original), original, + def->name) < 0) + goto cleanup; } } } @@ -644,10 +631,8 @@ static virDomainSnapshotObjPtr virDomainSnapshotObjNew(void) { virDomainSnapshotObjPtr snapshot; - if (VIR_ALLOC(snapshot) < 0) { - virReportOOMError(); + if (VIR_ALLOC(snapshot) < 0) return NULL; - } VIR_DEBUG("obj=%p", snapshot); @@ -703,10 +688,8 @@ virDomainSnapshotObjListPtr virDomainSnapshotObjListNew(void) { virDomainSnapshotObjListPtr snapshots; - if (VIR_ALLOC(snapshots) < 0) { - virReportOOMError(); + if (VIR_ALLOC(snapshots) < 0) return NULL; - } snapshots->objs = virHashCreate(50, virDomainSnapshotObjListDataFree); if (!snapshots->objs) { VIR_FREE(snapshots); @@ -1031,10 +1014,8 @@ virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots, if (!snaps || count < 0) return count; if (VIR_ALLOC_N(names, count) < 0 || - VIR_ALLOC_N(list, count + 1) < 0) { - virReportOOMError(); + VIR_ALLOC_N(list, count + 1) < 0) goto cleanup; - } if (virDomainSnapshotObjListGetNames(snapshots, from, names, count, flags) < 0) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 2539c45..507f6dd 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -569,10 +569,8 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, source->nhost = n; if (source->nhost) { - if (VIR_ALLOC_N(source->hosts, source->nhost) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(source->hosts, source->nhost) < 0) goto cleanup; - } for (i = 0; i < source->nhost; i++) { name = virXMLPropString(nodeset[i], "name"); @@ -605,7 +603,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, if (nsource > 0) { if (VIR_ALLOC_N(source->devices, nsource) < 0) { VIR_FREE(nodeset); - virReportOOMError(); goto cleanup; } @@ -728,10 +725,8 @@ virStoragePoolDefParseSourceString(const char *srcSpec, &xpath_ctxt))) goto cleanup; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (VIR_ALLOC(def) < 0) goto cleanup; - } if (!(node = virXPathNode("/source", xpath_ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -840,10 +835,8 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) char *uuid = NULL; char *target_path = NULL; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } type = virXPathString("string(./@type)", ctxt); if (type == NULL) { @@ -1267,10 +1260,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (options == NULL) return NULL; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->name = virXPathString("string(./name)", ctxt); if (ret->name == NULL) { @@ -1373,7 +1364,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, goto error; if (!(ret->target.features = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST))) - goto no_memory; + goto error; for (i = 0; i < n; i++) { int f = options->featureFromString((const char*)nodes[i]->name); @@ -1400,8 +1391,6 @@ cleanup: VIR_FREE(unit); return ret; -no_memory: - virReportOOMError(); error: virStorageVolDefFree(ret); ret = NULL; @@ -1743,10 +1732,8 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, return pool; } - if (VIR_ALLOC(pool) < 0) { - virReportOOMError(); + if (VIR_ALLOC(pool) < 0) return NULL; - } if (virMutexInit(&pool->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1762,7 +1749,6 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, pool->def = NULL; virStoragePoolObjUnlock(pool); virStoragePoolObjFree(pool); - virReportOOMError(); return NULL; } pools->objs[pools->count++] = pool; @@ -1933,10 +1919,8 @@ virStoragePoolSourceListNewSource(virStoragePoolSourceListPtr list) { virStoragePoolSourcePtr source; - if (VIR_REALLOC_N(list->sources, list->nsources + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(list->sources, list->nsources + 1) < 0) return NULL; - } source = &list->sources[list->nsources++]; memset(source, 0, sizeof(*source)); @@ -2215,12 +2199,8 @@ virStoragePoolObjListExport(virConnectPtr conn, int ret = -1; int i; - if (pools) { - if (VIR_ALLOC_N(tmp_pools, poolobjs.count + 1) < 0) { - virReportOOMError(); - goto cleanup; - } - } + if (pools && VIR_ALLOC_N(tmp_pools, poolobjs.count + 1) < 0) + goto cleanup; for (i = 0; i < poolobjs.count; i++) { virStoragePoolObjPtr poolobj = poolobjs.objs[i]; diff --git a/src/conf/storage_encryption_conf.c b/src/conf/storage_encryption_conf.c index c710bbd..f52500f 100644 --- a/src/conf/storage_encryption_conf.c +++ b/src/conf/storage_encryption_conf.c @@ -77,10 +77,8 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, int type; char *uuidstr = NULL; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } old_node = ctxt->node; ctxt->node = node; @@ -134,10 +132,8 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) char *format_str; int format, i, n; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } format_str = virXPathString("string(./@format)", ctxt); if (format_str == NULL) { @@ -160,10 +156,8 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) if (n < 0){ goto cleanup; } - if (n != 0 && VIR_ALLOC_N(ret->secrets, n) < 0) { - virReportOOMError(); + if (n != 0 && VIR_ALLOC_N(ret->secrets, n) < 0) goto cleanup; - } ret->nsecrets = n; for (i = 0; i < n; i++) { ret->secrets[i] = virStorageEncryptionSecretParse(ctxt, nodes[i]); diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c index 36fbb97..0ec184a 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -89,10 +89,8 @@ static char *virChrdevLockFilePath(const char *dev) ++p; } - if (virAsprintf(&path, "%s/LCK..%s", VIR_CHRDEV_LOCK_FILE_PATH, filename) < 0) { - virReportOOMError(); + if (virAsprintf(&path, "%s/LCK..%s", VIR_CHRDEV_LOCK_FILE_PATH, filename) < 0) goto cleanup; - } sanitizedPath = virFileSanitizePath(path); @@ -138,10 +136,8 @@ static int virChrdevLockFileCreate(const char *dev) /* ensure correct format according to filesystem hierarchy standard */ /* http://www.pathname.com/fhs/pub/fhs-2.3.html#VARLOCKLOCKFILES */ - if (virAsprintf(&pidStr, "%10lld\n", (long long) getpid()) < 0) { - virReportOOMError(); + if (virAsprintf(&pidStr, "%10lld\n", (long long) getpid()) < 0) goto cleanup; - } /* create the lock file */ if ((lockfd = open(path, O_WRONLY | O_CREAT | O_EXCL, 00644)) < 0) { @@ -396,10 +392,8 @@ int virChrdevOpen(virChrdevsPtr devs, return -1; } - if (VIR_ALLOC(cbdata) < 0) { - virReportOOMError(); + if (VIR_ALLOC(cbdata) < 0) goto error; - } if (virHashAddEntry(devs->hash, path, st) < 0) goto error; -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list