[libvirt PATCH v2 15/15] nwfilter: convert remaining VIR_FREE() to g_free()

Laine Stump posted 15 patches 4 years, 4 months ago
[libvirt PATCH v2 15/15] nwfilter: convert remaining VIR_FREE() to g_free()
Posted by Laine Stump 4 years, 4 months ago
Signed-off-by: Laine Stump <laine@redhat.com>
---
 src/nwfilter/nwfilter_dhcpsnoop.c         | 16 ++++++++--------
 src/nwfilter/nwfilter_driver.c            | 10 +++++-----
 src/nwfilter/nwfilter_ebiptables_driver.c |  2 +-
 src/nwfilter/nwfilter_gentech_driver.c    |  6 +++---
 src/nwfilter/nwfilter_learnipaddr.c       |  8 ++++----
 5 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index 64671af135..aafa6de322 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -314,7 +314,7 @@ virNWFilterSnoopCancel(char **threadKey)
     virNWFilterSnoopActiveLock();
 
     ignore_value(virHashRemoveEntry(virNWFilterSnoopState.active, *threadKey));
-    VIR_FREE(*threadKey);
+    g_free(*threadKey);
 
     virNWFilterSnoopActiveUnlock();
 }
@@ -600,7 +600,7 @@ virNWFilterSnoopReqFree(virNWFilterSnoopReqPtr req)
     virCondDestroy(&req->threadStatusCond);
     virFreeError(req->threadError);
 
-    VIR_FREE(req);
+    g_free(req);
 }
 
 /*
@@ -731,7 +731,7 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req,
 
     if (req->threadkey && virNWFilterSnoopIPLeaseInstallRule(pl, true) < 0) {
         virNWFilterSnoopReqUnlock(req);
-        VIR_FREE(pl);
+        g_free(pl);
         return -1;
     }
 
@@ -850,7 +850,7 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req,
     }
 
  skip_instantiate:
-    VIR_FREE(ipl);
+    g_free(ipl);
 
     ignore_value(!!g_atomic_int_dec_and_test(&virNWFilterSnoopState.nLeases));
 
@@ -1149,7 +1149,7 @@ virNWFilterSnoopDHCPDecodeJobSubmit(virThreadPoolPtr pool,
     if (ret == 0)
         g_atomic_int_add(qCtr, 1);
     else
-        VIR_FREE(job);
+        g_free(job);
 
     return ret;
 }
@@ -1502,7 +1502,7 @@ virNWFilterDHCPSnoopThread(void *req0)
     ignore_value(virHashRemoveEntry(virNWFilterSnoopState.ifnameToKey,
                                     req->binding->portdevname));
 
-    VIR_FREE(req->binding->portdevname);
+    g_clear_pointer(&req->binding->portdevname, g_free);
 
     virNWFilterSnoopReqUnlock(req);
     virNWFilterSnoopUnlock();
@@ -1970,7 +1970,7 @@ virNWFilterSnoopRemAllReqIter(const void *payload,
          */
         virNWFilterIPAddrMapDelIPAddr(req->binding->portdevname, NULL);
 
-        VIR_FREE(req->binding->portdevname);
+        g_clear_pointer(&req->binding->portdevname, g_free);
     }
 
     virNWFilterSnoopReqUnlock(req);
@@ -2079,7 +2079,7 @@ virNWFilterDHCPSnoopEnd(const char *ifname)
         /* keep valid lease req; drop interface association */
         virNWFilterSnoopCancel(&req->threadkey);
 
-        VIR_FREE(req->binding->portdevname);
+        g_clear_pointer(&req->binding->portdevname, g_free);
 
         virNWFilterSnoopReqUnlock(req);
 
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 39d0a2128e..7853ad59fa 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -303,7 +303,7 @@ nwfilterStateInitialize(bool privileged,
 
  err_free_driverstate:
     virNWFilterObjListFree(driver->nwfilters);
-    VIR_FREE(driver);
+    g_free(driver);
 
     return VIR_DRV_STATE_INIT_ERROR;
 }
@@ -367,9 +367,9 @@ nwfilterStateCleanup(void)
         if (driver->lockFD != -1)
             virPidFileRelease(driver->stateDir, "driver", driver->lockFD);
 
-        VIR_FREE(driver->stateDir);
-        VIR_FREE(driver->configDir);
-        VIR_FREE(driver->bindingDir);
+        g_free(driver->stateDir);
+        g_free(driver->configDir);
+        g_free(driver->bindingDir);
         nwfilterDriverUnlock();
     }
 
@@ -379,7 +379,7 @@ nwfilterStateCleanup(void)
     virNWFilterObjListFree(driver->nwfilters);
 
     virMutexDestroy(&driver->lock);
-    VIR_FREE(driver);
+    g_free(driver);
 
     return 0;
 }
diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c
index 9c9d63f14b..6aefbe226b 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -3517,7 +3517,7 @@ ebiptablesApplyNewRules(const char *ifname,
 
  cleanup:
     for (i = 0; i < nsubchains; i++)
-        VIR_FREE(subchains[i]);
+        g_free(subchains[i]);
 
     return ret;
 }
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 071f15caea..c93f2ed18f 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -122,7 +122,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst)
         return;
 
     virHashFree(inst->vars);
-    VIR_FREE(inst);
+    g_free(inst);
 }
 
 
@@ -234,12 +234,12 @@ virNWFilterInstReset(virNWFilterInstPtr inst)
 
     for (i = 0; i < inst->nfilters; i++)
         virNWFilterObjUnlock(inst->filters[i]);
-    VIR_FREE(inst->filters);
+    g_free(inst->filters);
     inst->nfilters = 0;
 
     for (i = 0; i < inst->nrules; i++)
         virNWFilterRuleInstFree(inst->rules[i]);
-    VIR_FREE(inst->rules);
+    g_free(inst->rules);
     inst->nrules = 0;
 }
 
diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c
index abef0b6457..c6497450eb 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -156,7 +156,7 @@ virNWFilterLockIface(const char *ifname)
         if (virMutexInitRecursive(&ifaceLock->lock) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("mutex initialization failed"));
-            VIR_FREE(ifaceLock);
+            g_free(ifaceLock);
             goto error;
         }
 
@@ -165,12 +165,12 @@ virNWFilterLockIface(const char *ifname)
                            _("interface name %s does not fit into "
                              "buffer "),
                            ifaceLock->ifname);
-            VIR_FREE(ifaceLock);
+            g_free(ifaceLock);
             goto error;
         }
 
         while (virHashAddEntry(ifaceLockMap, ifname, ifaceLock)) {
-            VIR_FREE(ifaceLock);
+            g_free(ifaceLock);
             goto error;
         }
 
@@ -221,7 +221,7 @@ virNWFilterIPAddrLearnReqFree(virNWFilterIPAddrLearnReqPtr req)
 
     virNWFilterBindingDefFree(req->binding);
 
-    VIR_FREE(req);
+    g_free(req);
 }
 
 
-- 
2.25.4

Re: [libvirt PATCH v2 15/15] nwfilter: convert remaining VIR_FREE() to g_free()
Posted by Ján Tomko 4 years, 4 months ago
On a Tuesday in 2020, Laine Stump wrote:
>Signed-off-by: Laine Stump <laine@redhat.com>
>---
> src/nwfilter/nwfilter_dhcpsnoop.c         | 16 ++++++++--------
> src/nwfilter/nwfilter_driver.c            | 10 +++++-----
> src/nwfilter/nwfilter_ebiptables_driver.c |  2 +-
> src/nwfilter/nwfilter_gentech_driver.c    |  6 +++---
> src/nwfilter/nwfilter_learnipaddr.c       |  8 ++++----
> 5 files changed, 21 insertions(+), 21 deletions(-)
>
>diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
>index 64671af135..aafa6de322 100644
>--- a/src/nwfilter/nwfilter_dhcpsnoop.c
>+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
>@@ -314,7 +314,7 @@ virNWFilterSnoopCancel(char **threadKey)
>     virNWFilterSnoopActiveLock();
>
>     ignore_value(virHashRemoveEntry(virNWFilterSnoopState.active, *threadKey));
>-    VIR_FREE(*threadKey);
>+    g_free(*threadKey);

This one should use g_clear_pointer.

>
>     virNWFilterSnoopActiveUnlock();
> }
>diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
>index 39d0a2128e..7853ad59fa 100644
>--- a/src/nwfilter/nwfilter_driver.c
>+++ b/src/nwfilter/nwfilter_driver.c
>@@ -303,7 +303,7 @@ nwfilterStateInitialize(bool privileged,
>
>  err_free_driverstate:
>     virNWFilterObjListFree(driver->nwfilters);
>-    VIR_FREE(driver);
>+    g_free(driver);

Same here.

>
>     return VIR_DRV_STATE_INIT_ERROR;
> }
>@@ -379,7 +379,7 @@ nwfilterStateCleanup(void)
>     virNWFilterObjListFree(driver->nwfilters);
>
>     virMutexDestroy(&driver->lock);
>-    VIR_FREE(driver);
>+    g_free(driver);
>

Possibly here.

>     return 0;
> }

(I have not verified whether the double use of the pointer may
practically happen, but we do a non-NULL check of these in a few cases)

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano