From 0ca51d5c9f7b935d2d7e1a1f081980d4bb010898 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 3 May 2013 14:45:04 +0200 Subject: [PATCH] Adapt to VIR_STRDUP and VIR_STRNDUP in src/nwfilter/* --- src/nwfilter/nwfilter_dhcpsnoop.c | 22 +++++++++++----------- src/nwfilter/nwfilter_driver.c | 7 +++---- src/nwfilter/nwfilter_ebiptables_driver.c | 2 +- src/nwfilter/nwfilter_gentech_driver.c | 5 ++--- src/nwfilter/nwfilter_learnipaddr.c | 5 +---- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index 50042dfa4c..328f90ec98 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -133,11 +133,11 @@ struct _virNWFilterSnoopReq { virNWFilterTechDriverPtr techdriver; char *ifname; int ifindex; - const char *linkdev; + char *linkdev; enum virDomainNetType nettype; char ifkey[VIR_IFKEY_LEN]; virMacAddr macaddr; - const char *filtername; + char *filtername; virNWFilterHashTablePtr vars; virNWFilterDriverStatePtr driver; /* start and end of lease list, ordered by lease time */ @@ -1110,10 +1110,8 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAddr *mac, * generate much more traffic than if we filtered by VM and * braodcast MAC as well */ - if (!(ext_filter = strdup(filter))) { - virReportOOMError(); + if (VIR_STRDUP(ext_filter, filter) < 0) return NULL; - } } handle = pcap_create(ifname, pcap_errbuf); @@ -1408,7 +1406,7 @@ virNWFilterDHCPSnoopThread(void *req0) fds[i].fd = pcap_fileno(pcapConf[i].handle); } tmp = virNetDevGetIndex(req->ifname, &ifindex); - threadkey = strdup(req->threadkey); + ignore_value(VIR_STRDUP(threadkey, req->threadkey)); worker = virThreadPoolNew(1, 1, 0, virNWFilterDHCPDecodeWorker, req); @@ -1631,15 +1629,17 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver, req->driver = driver; req->techdriver = techdriver; tmp = virNetDevGetIndex(ifname, &req->ifindex); - req->linkdev = linkdev ? strdup(linkdev) : NULL; req->nettype = nettype; - req->ifname = strdup(ifname); virMacAddrSet(&req->macaddr, macaddr); - req->filtername = strdup(filtername); req->vars = virNWFilterHashTableCreate(0); + req->linkdev = NULL; - if (!req->ifname || !req->filtername || !req->vars || tmp < 0 || - (linkdev != NULL && req->linkdev == NULL)) { + if (VIR_STRDUP(req->ifname, ifname) < 0 || + VIR_STRDUP(req->filtername, filtername) < 0 || + VIR_STRDUP(req->linkdev, linkdev) < 0) + goto exit_snoopreqput; + + if (!req->vars || tmp < 0) { virReportOOMError(); goto exit_snoopreqput; } diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 7eec3de40b..64ea251d89 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -221,8 +221,8 @@ nwfilterStateInitialize(bool privileged, goto error; } - if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL) - goto out_of_memory; + if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0) + goto error; if (virAsprintf(&driverState->configDir, "%s/nwfilter", base) == -1) @@ -454,9 +454,8 @@ nwfilterConnectListNWFilters(virConnectPtr conn, nwfilterDriverLock(driver); for (i = 0 ; i < driver->nwfilters.count && got < nnames ; i++) { virNWFilterObjLock(driver->nwfilters.objs[i]); - if (!(names[got] = strdup(driver->nwfilters.objs[i]->def->name))) { + if (VIR_STRDUP(names[got], driver->nwfilters.objs[i]->def->name) < 0) { virNWFilterObjUnlock(driver->nwfilters.objs[i]); - virReportOOMError(); goto cleanup; } got++; diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index ac943555ea..2936571e8a 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -2982,7 +2982,7 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst, switch (protoidx) { case L2_PROTO_MAC_IDX: - protostr = strdup(""); + ignore_value(VIR_STRDUP(protostr, "")); break; case L2_PROTO_STP_IDX: ignore_value(virAsprintf(&protostr, "-d " NWFILTER_MAC_BGA " ")); diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 958f47a0c2..7bca2f4abe 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -37,6 +37,7 @@ #include "nwfilter_learnipaddr.h" #include "virnetdev.h" #include "datatypes.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NWFILTER @@ -866,9 +867,7 @@ __virNWFilterInstantiateFilter(const unsigned char *vmuuid, } virMacAddrFormat(macaddr, vmmacaddr); - str_macaddr = strdup(vmmacaddr); - if (!str_macaddr) { - virReportOOMError(); + if (VIR_STRDUP(str_macaddr, vmmacaddr) < 0) { rc = -1; goto err_exit; } diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index 8eb7700534..2b493337f9 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -705,11 +705,8 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver, if (virNWFilterHashTablePutAll(filterparams, ht) < 0) goto err_free_ht; - req->filtername = strdup(filtername); - if (req->filtername == NULL) { - virReportOOMError(); + if (VIR_STRDUP(req->filtername, filtername) < 0) goto err_free_ht; - } if (virStrcpyStatic(req->ifname, ifname) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR,