[PATCH v2 14/37] Adapt to VIR_STRDUP in src/nwfilter/*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/nwfilter/nwfilter_dhcpsnoop.c         | 15 +++++++--------
 src/nwfilter/nwfilter_driver.c            |  4 ++--
 src/nwfilter/nwfilter_ebiptables_driver.c | 10 +++++-----
 src/nwfilter/nwfilter_gentech_driver.c    |  4 ++--
 src/nwfilter/nwfilter_learnipaddr.c       |  3 +--
 5 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index df11e89..3047d4d 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 */
@@ -1408,7 +1408,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 +1631,14 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
     req->driver = driver;
     req->techdriver = techdriver;
     tmp = virNetDevGetIndex(ifname, &req->ifindex);
-    req->linkdev = linkdev ? strdup(linkdev) : NULL;
+    req->linkdev = NULL;
     req->nettype = nettype;
-    req->ifname = strdup(ifname);
     virMacAddrSet(&req->macaddr, macaddr);
-    req->filtername = strdup(filtername);
     req->vars = virNWFilterHashTableCreate(0);
 
-    if (!req->ifname || !req->filtername || !req->vars || tmp < 0 ||
-        (linkdev != NULL && req->linkdev == NULL)) {
+    if ((linkdev && VIR_STRDUP(req->linkdev, linkdev) < 0) ||
+        VIR_STRDUP(req->ifname, ifname) < 0 ||
+        VIR_STRDUP(req->filtername, filtername) < 0 || !req->vars || tmp < 0) {
         virReportOOMError();
         goto exit_snoopreqput;
     }
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 7eec3de..0a3c24f 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -221,7 +221,7 @@ nwfilterStateInitialize(bool privileged,
         goto error;
     }
 
-    if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL)
+    if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0)
         goto out_of_memory;
 
     if (virAsprintf(&driverState->configDir,
@@ -454,7 +454,7 @@ 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;
diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c
index ac94355..5d1c8d7 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -2975,6 +2975,7 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst,
     char chainPrefix = (incoming) ? CHAINPREFIX_HOST_IN_TEMP
                                   : CHAINPREFIX_HOST_OUT_TEMP;
     char *protostr = NULL;
+    int rc;
 
     PRINT_ROOT_CHAIN(rootchain, chainPrefix, ifname);
     PRINT_CHAIN(chain, chainPrefix, ifname,
@@ -2982,18 +2983,17 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst,
 
     switch (protoidx) {
     case L2_PROTO_MAC_IDX:
-        protostr = strdup("");
+        rc = VIR_STRDUP(protostr, "");
         break;
     case L2_PROTO_STP_IDX:
-        ignore_value(virAsprintf(&protostr, "-d " NWFILTER_MAC_BGA " "));
+        rc = virAsprintf(&protostr, "-d " NWFILTER_MAC_BGA " ");
         break;
     default:
-        ignore_value(virAsprintf(&protostr, "-p 0x%04x ",
-                     l3_protocols[protoidx].attr));
+        rc = virAsprintf(&protostr, "-p 0x%04x ", l3_protocols[protoidx].attr);
         break;
     }
 
-    if (!protostr) {
+    if (rc < 0) {
         virReportOOMError();
         return -1;
     }
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 958f47a..90f38f3 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,8 +867,7 @@ __virNWFilterInstantiateFilter(const unsigned char *vmuuid,
     }
 
     virMacAddrFormat(macaddr, vmmacaddr);
-    str_macaddr = strdup(vmmacaddr);
-    if (!str_macaddr) {
+    if (VIR_STRDUP(str_macaddr, vmmacaddr) < 0) {
         virReportOOMError();
         rc = -1;
         goto err_exit;
diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c
index 14fd32c..d945af2 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -705,8 +705,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
     if (virNWFilterHashTablePutAll(filterparams, ht) < 0)
         goto err_free_ht;
 
-    req->filtername = strdup(filtername);
-    if (req->filtername == NULL) {
+    if (VIR_STRDUP(req->filtername, filtername) < 0) {
         virReportOOMError();
         goto err_free_ht;
     }
-- 
1.8.1.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]