--- src/nwfilter/nwfilter_dhcpsnoop.c | 29 +++++-------------- src/nwfilter/nwfilter_driver.c | 13 ++------- src/nwfilter/nwfilter_ebiptables_driver.c | 46 ++++++++++--------------------- src/nwfilter/nwfilter_gentech_driver.c | 24 ++++------------ src/nwfilter/nwfilter_learnipaddr.c | 12 ++------ 5 files changed, 33 insertions(+), 91 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index 708e67f..d21d6ef 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -303,10 +303,8 @@ virNWFilterSnoopActivate(virNWFilterSnoopReqPtr req) { char *key; - if (virAsprintf(&key, "%p-%d", req, req->ifindex) < 0) { - virReportOOMError(); + if (virAsprintf(&key, "%p-%d", req, req->ifindex) < 0) return NULL; - } virNWFilterSnoopActiveLock(); @@ -583,10 +581,8 @@ virNWFilterSnoopReqNew(const char *ifkey) return NULL; } - if (VIR_ALLOC(req) < 0) { - virReportOOMError(); + if (VIR_ALLOC(req) < 0) return NULL; - } req->threadStatus = THREAD_STATUS_NONE; @@ -762,10 +758,8 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req, virNWFilterSnoopReqUnlock(req); - if (VIR_ALLOC(pl) < 0) { - virReportOOMError(); + if (VIR_ALLOC(pl) < 0) return -1; - } *pl = *plnew; /* protect req->threadkey */ @@ -1091,10 +1085,8 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAddr *mac, * more unlikely parameters first, then go for the MAC */ if (virAsprintf(&ext_filter, - "%s and ether src %s", filter, macaddr) < 0) { - virReportOOMError(); + "%s and ether src %s", filter, macaddr) < 0) return NULL; - } } else { /* * Some DHCP servers respond via MAC broadcast; we rely on later @@ -1195,10 +1187,8 @@ virNWFilterSnoopDHCPDecodeJobSubmit(virThreadPoolPtr pool, if (len <= MIN_VALID_DHCP_PKT_SIZE || len > sizeof(job->packet)) return 0; - if (VIR_ALLOC(job) < 0) { - virReportOOMError(); + if (VIR_ALLOC(job) < 0) return -1; - } memcpy(job->packet, pep, len); job->caplen = len; @@ -1633,10 +1623,8 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver, VIR_STRDUP(req->linkdev, linkdev) < 0) goto exit_snoopreqput; - if (!req->vars || tmp < 0) { - virReportOOMError(); + if (!req->vars || tmp < 0) goto exit_snoopreqput; - } /* check that all tools are available for applying the filters (late) */ if (!techdriver->canApplyBasicRules()) { @@ -1781,7 +1769,6 @@ virNWFilterSnoopLeaseFileWrite(int lfd, const char *ifkey, ifkey, ipstr, dhcpstr); if (len < 0) { - virReportOOMError(); ret = -1; goto cleanup; } @@ -2089,10 +2076,8 @@ virNWFilterDHCPSnoopInit(void) if (!virNWFilterSnoopState.ifnameToKey || !virNWFilterSnoopState.snoopReqs || - !virNWFilterSnoopState.active) { - virReportOOMError(); + !virNWFilterSnoopState.active) goto err_exit; - } virNWFilterSnoopLeaseFileLoad(); virNWFilterSnoopLeaseFileOpen(); diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 0fbc940..e264ef9 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -178,10 +178,8 @@ nwfilterStateInitialize(bool privileged, sysbus = virDBusGetSystemBus(); #endif /* WITH_DBUS */ - if (VIR_ALLOC(driverState) < 0) { - virReportOOMError(); + if (VIR_ALLOC(driverState) < 0) return -1; - } if (virMutexInit(&driverState->lock) < 0) goto err_free_driverstate; @@ -227,7 +225,7 @@ nwfilterStateInitialize(bool privileged, if (virAsprintf(&driverState->configDir, "%s/nwfilter", base) == -1) - goto out_of_memory; + goto error; VIR_FREE(base); @@ -240,9 +238,6 @@ nwfilterStateInitialize(bool privileged, return 0; -out_of_memory: - virReportOOMError(); - error: VIR_FREE(base); nwfilterDriverUnlock(driverState); @@ -518,10 +513,8 @@ nwfilterConnectListAllNWFilters(virConnectPtr conn, goto cleanup; } - if (VIR_ALLOC_N(tmp_filters, driver->nwfilters.count + 1) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(tmp_filters, driver->nwfilters.count + 1) < 0) goto cleanup; - } for (i = 0; i < driver->nwfilters.count; i++) { obj = driver->nwfilters.objs[i]; diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index 9a54de4..ab9e20f 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -494,10 +494,8 @@ ebiptablesAddRuleInst(virNWFilterRuleInstPtr res, { ebiptablesRuleInstPtr inst; - if (VIR_ALLOC(inst) < 0) { - virReportOOMError(); + if (VIR_ALLOC(inst) < 0) return -1; - } inst->commandTemplate = commandTemplate; inst->neededProtocolChain = neededChain; @@ -3016,10 +3014,8 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst, break; } - if (!protostr) { - virReportOOMError(); + if (!protostr) return -1; - } virBufferAsprintf(&buf, CMD_DEF("$EBT -t nat -F %s") CMD_SEPARATOR @@ -3393,10 +3389,8 @@ ebtablesApplyDHCPOnlyRules(const char *ifname, dhcpserver = virNWFilterVarValueGetNthValue(dhcpsrvrs, idx); - if (virAsprintf(&srcIPParam, "--ip-src %s", dhcpserver) < 0) { - virReportOOMError(); + if (virAsprintf(&srcIPParam, "--ip-src %s", dhcpserver) < 0) goto tear_down_tmpebchains; - } } /* @@ -3720,10 +3714,8 @@ ebiptablesApplyNewRules(const char *ifname, if (inst == NULL) nruleInstances = 0; - if (!chains_in_set || !chains_out_set) { - virReportOOMError(); + if (!chains_in_set || !chains_out_set) goto exit_free_sets; - } if (nruleInstances > 1 && inst) qsort(inst, nruleInstances, sizeof(inst[0]), @@ -3736,16 +3728,12 @@ ebiptablesApplyNewRules(const char *ifname, const char *name = inst[i]->neededProtocolChain; if (inst[i]->chainprefix == CHAINPREFIX_HOST_IN_TEMP) { if (virHashUpdateEntry(chains_in_set, name, - &inst[i]->chainPriority) < 0) { - virReportOOMError(); + &inst[i]->chainPriority) < 0) goto exit_free_sets; - } } else { if (virHashUpdateEntry(chains_out_set, name, - &inst[i]->chainPriority) < 0) { - virReportOOMError(); + &inst[i]->chainPriority) < 0) goto exit_free_sets; - } } } } @@ -4210,19 +4198,15 @@ ebiptablesDriverInitWithFirewallD(void) } else { VIR_INFO("firewalld support enabled for nwfilter"); - ignore_value(virAsprintf(&ebtables_cmd_path, - "%s --direct --passthrough eb", - firewall_cmd_path)); - ignore_value(virAsprintf(&iptables_cmd_path, - "%s --direct --passthrough ipv4", - firewall_cmd_path)); - ignore_value(virAsprintf(&ip6tables_cmd_path, - "%s --direct --passthrough ipv6", - firewall_cmd_path)); - - if (!ebtables_cmd_path || !iptables_cmd_path || - !ip6tables_cmd_path) { - virReportOOMError(); + if (virAsprintf(&ebtables_cmd_path, + "%s --direct --passthrough eb", + firewall_cmd_path) < 0 || + virAsprintf(&iptables_cmd_path, + "%s --direct --passthrough ipv4", + firewall_cmd_path) < 0 || + virAsprintf(&ip6tables_cmd_path, + "%s --direct --passthrough ipv6", + firewall_cmd_path) < 0) { VIR_FREE(ebtables_cmd_path); VIR_FREE(iptables_cmd_path); VIR_FREE(ip6tables_cmd_path); diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 4180505..47f6dfb 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -110,10 +110,8 @@ int virNWFilterRuleInstAddData(virNWFilterRuleInstPtr res, void *data) { - if (VIR_REALLOC_N(res->data, res->ndata+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(res->data, res->ndata+1) < 0) return -1; - } res->data[res->ndata++] = data; return 0; } @@ -201,10 +199,8 @@ virNWFilterHashTablePtr virNWFilterCreateVarHashmap(char *macaddr, const virNWFilterVarValuePtr ipaddr) { virNWFilterHashTablePtr table = virNWFilterHashTableCreate(0); - if (!table) { - virReportOOMError(); + if (!table) return NULL; - } if (virNWFilterVarHashmapAddStdValues(table, macaddr, ipaddr) < 0) { virNWFilterHashTableFree(table); @@ -303,10 +299,8 @@ virNWFilterRuleInstantiate(virNWFilterTechDriverPtr techdriver, int i; virNWFilterRuleInstPtr ret; - if (VIR_ALLOC(ret) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ret) < 0) return NULL; - } ret->techdriver = techdriver; @@ -340,10 +334,8 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1, virNWFilterHashTablePtr vars2) { virNWFilterHashTablePtr res = virNWFilterHashTableCreate(0); - if (!res) { - virReportOOMError(); + if (!res) return NULL; - } if (virNWFilterHashTablePutAll(vars1, res) < 0) goto err_exit; @@ -415,7 +407,6 @@ _virNWFilterInstantiateRec(virNWFilterTechDriverPtr techdriver, } if (VIR_REALLOC_N(*insts, (*nEntries)+1) < 0) { - virReportOOMError(); rc = -1; break; } @@ -441,7 +432,6 @@ _virNWFilterInstantiateRec(virNWFilterTechDriverPtr techdriver, virNWFilterCreateVarsFrom(inc->params, vars); if (!tmpvars) { - virReportOOMError(); rc = -1; virNWFilterObjUnlock(obj); break; @@ -553,7 +543,6 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter, virNWFilterCreateVarsFrom(inc->params, vars); if (!tmpvars) { - virReportOOMError(); rc = -1; virNWFilterObjUnlock(obj); break; @@ -611,10 +600,8 @@ virNWFilterRuleInstancesToArray(int nEntries, if ((*nptrs) == 0) return 0; - if (VIR_ALLOC_N((*ptrs), (*nptrs)) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N((*ptrs), (*nptrs)) < 0) return -1; - } (*nptrs) = 0; @@ -674,7 +661,6 @@ virNWFilterInstantiate(const unsigned char *vmuuid ATTRIBUTE_UNUSED, virNWFilterHashTablePtr missing_vars = virNWFilterHashTableCreate(0); if (!missing_vars) { - virReportOOMError(); rc = -1; goto err_exit; } diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index eabcf94..7e67203 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -143,10 +143,8 @@ virNWFilterLockIface(const char *ifname) { ifaceLock = virHashLookup(ifaceLockMap, ifname); if (!ifaceLock) { - if (VIR_ALLOC(ifaceLock) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ifaceLock) < 0) goto err_exit; - } if (virMutexInitRecursive(&ifaceLock->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -699,16 +697,12 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver, return -1; } - if (VIR_ALLOC(req) < 0) { - virReportOOMError(); + if (VIR_ALLOC(req) < 0) goto err_no_req; - } ht = virNWFilterHashTableCreate(0); - if (ht == NULL) { - virReportOOMError(); + if (ht == NULL) goto err_free_req; - } if (virNWFilterHashTablePutAll(filterparams, ht) < 0) goto err_free_ht; -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list