[PATCH 19/25] nwfilter replace VIR_ALLOC with g_new0

Laine Stump laine at redhat.com
Thu Jun 25 03:34:08 UTC 2020


Signed-off-by: Laine Stump <laine at redhat.com>
---
 src/nwfilter/nwfilter_dhcpsnoop.c         | 9 +++------
 src/nwfilter/nwfilter_driver.c            | 3 +--
 src/nwfilter/nwfilter_ebiptables_driver.c | 3 +--
 src/nwfilter/nwfilter_gentech_driver.c    | 3 +--
 src/nwfilter/nwfilter_learnipaddr.c       | 6 ++----
 5 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index f530341872..f54e1a88e0 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -562,8 +562,7 @@ virNWFilterSnoopReqNew(const char *ifkey)
         return NULL;
     }
 
-    if (VIR_ALLOC(req) < 0)
-        return NULL;
+    req = g_new0(virNWFilterSnoopReq, 1);
 
     req->threadStatus = THREAD_STATUS_NONE;
 
@@ -737,8 +736,7 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req,
 
     virNWFilterSnoopReqUnlock(req);
 
-    if (VIR_ALLOC(pl) < 0)
-        return -1;
+    pl = g_new0(virNWFilterSnoopIPLease, 1);
     *pl = *plnew;
 
     /* protect req->threadkey */
@@ -1160,8 +1158,7 @@ virNWFilterSnoopDHCPDecodeJobSubmit(virThreadPoolPtr pool,
     if (len <= MIN_VALID_DHCP_PKT_SIZE || len > sizeof(job->packet))
         return 0;
 
-    if (VIR_ALLOC(job) < 0)
-        return -1;
+    job = g_new0(virNWFilterDHCPDecodeJob, 1);
 
     memcpy(job->packet, pep, len);
     job->caplen = len;
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 1c407727db..39d0a2128e 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -193,8 +193,7 @@ nwfilterStateInitialize(bool privileged,
         !(sysbus = virDBusGetSystemBus()))
         return VIR_DRV_STATE_INIT_ERROR;
 
-    if (VIR_ALLOC(driver) < 0)
-        return VIR_DRV_STATE_INIT_ERROR;
+    driver = g_new0(virNWFilterDriverState, 1);
 
     driver->lockFD = -1;
     if (virMutexInit(&driver->lock) < 0)
diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c
index cc814235aa..89c131e17f 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -3318,8 +3318,7 @@ ebtablesGetSubChainInsts(virHashTablePtr chains,
         if ((int)idx < 0)
             continue;
 
-        if (VIR_ALLOC(inst) < 0)
-            goto cleanup;
+        inst = g_new0(ebtablesSubChainInst, 1);
         inst->priority = *(const virNWFilterChainPriority *)filter_names[i].value;
         inst->incoming = incoming;
         inst->protoidx = idx;
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 6789a4a3fa..8ba555358d 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -261,8 +261,7 @@ virNWFilterRuleDefToRuleInst(virNWFilterDefPtr def,
     virNWFilterRuleInstPtr ruleinst;
     int ret = -1;
 
-    if (VIR_ALLOC(ruleinst) < 0)
-        goto cleanup;
+    ruleinst = g_new0(virNWFilterRuleInst, 1);
 
     ruleinst->chainSuffix = def->chainsuffix;
     ruleinst->chainPriority = def->chainPriority;
diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c
index 4ce8d5ba03..3bb8c27167 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -151,8 +151,7 @@ virNWFilterLockIface(const char *ifname)
 
     ifaceLock = virHashLookup(ifaceLockMap, ifname);
     if (!ifaceLock) {
-        if (VIR_ALLOC(ifaceLock) < 0)
-            goto err_exit;
+        ifaceLock = g_new0(virNWFilterIfaceLock, 1);
 
         if (virMutexInitRecursive(&ifaceLock->lock) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -718,8 +717,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
         return -1;
     }
 
-    if (VIR_ALLOC(req) < 0)
-        return -1;
+    req = g_new0(virNWFilterIPAddrLearnReq, 1);
 
     if (!(req->binding = virNWFilterBindingDefCopy(binding)))
         goto err_free_req;
-- 
2.25.4




More information about the libvir-list mailing list