[libvirt PATCH 08/24] tests: nwfilter: use g_autofree

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

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 tests/nwfilterebiptablestest.c   | 21 +++++++--------------
 tests/nwfilterxml2firewalltest.c | 12 ++++--------
 tests/nwfilterxml2xmltest.c      | 10 +++-------
 3 files changed, 14 insertions(+), 29 deletions(-)

diff --git a/tests/nwfilterebiptablestest.c b/tests/nwfilterebiptablestest.c
index 65b63959fb..7b32e90d19 100644
--- a/tests/nwfilterebiptablestest.c
+++ b/tests/nwfilterebiptablestest.c
@@ -101,7 +101,7 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque G_GNUC_UNUSED)
         "ebtables --concurrent -t nat -X libvirt-I-vnet0\n"
         "ebtables --concurrent -t nat -F libvirt-O-vnet0\n"
         "ebtables --concurrent -t nat -X libvirt-O-vnet0\n";
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
@@ -119,7 +119,6 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
@@ -167,7 +166,7 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque G_GNUC_UNUSED)
         "ebtables --concurrent -t nat -L libvirt-P-vnet0\n"
         "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n"
         "ebtables --concurrent -t nat -E libvirt-P-vnet0 libvirt-O-vnet0\n";
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
@@ -185,7 +184,6 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
@@ -211,7 +209,7 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaque G_GNUC_UNUSED)
         "ebtables --concurrent -t nat -X libvirt-J-vnet0\n"
         "ebtables --concurrent -t nat -F libvirt-P-vnet0\n"
         "ebtables --concurrent -t nat -X libvirt-P-vnet0\n";
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
@@ -229,7 +227,6 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaque G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
@@ -240,7 +237,7 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque G_GNUC_UNUSED)
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     const char *expected =
         VIR_NWFILTER_NEW_RULES_TEARDOWN;
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
@@ -258,7 +255,6 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
@@ -306,7 +302,7 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaque G_GNUC_UNUSED)
         "ebtables --concurrent -t nat -A libvirt-J-vnet0 -j DROP\n"
         "ebtables --concurrent -t nat -A PREROUTING -i vnet0 -j libvirt-J-vnet0\n"
         "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n";
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
     virMacAddr mac = { .addr = { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 } };
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
@@ -325,7 +321,6 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaque G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
@@ -381,7 +376,7 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *opaque G_GNUC_UNUSED)
         "ebtables --concurrent -t nat -A POSTROUTING -o vnet0 -j libvirt-P-vnet0\n"
         "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n"
         "ebtables --concurrent -t nat -E libvirt-P-vnet0 libvirt-O-vnet0\n";
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
     virMacAddr mac = { .addr = { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 } };
     const char *servers[] = { "192.168.122.1", "10.0.0.1", "10.0.0.2" };
@@ -410,7 +405,6 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *opaque G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
@@ -460,7 +454,7 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opaque G_GNUC_UNUSED)
         "ebtables --concurrent -t nat -A POSTROUTING -o vnet0 -j libvirt-P-vnet0\n"
         "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n"
         "ebtables --concurrent -t nat -E libvirt-P-vnet0 libvirt-O-vnet0\n";
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
@@ -478,7 +472,6 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opaque G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c
index 7fefd3ce75..3e8436a98c 100644
--- a/tests/nwfilterxml2firewalltest.c
+++ b/tests/nwfilterxml2firewalltest.c
@@ -229,7 +229,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDef *inc,
 {
     GHashTable *tmpvars = NULL;
     int ret = -1;
-    char *xml;
+    g_autofree char *xml = NULL;
 
     xml = g_strdup_printf("%s/nwfilterxml2firewalldata/%s.xml", abs_srcdir,
                           inc->filterref);
@@ -249,7 +249,6 @@ virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDef *inc,
     if (ret < 0)
         virNWFilterInstReset(inst);
     virHashFree(tmpvars);
-    VIR_FREE(xml);
     return ret;
 }
 
@@ -350,7 +349,7 @@ static int testSetDefaultParameters(GHashTable *vars)
 static int testCompareXMLToArgvFiles(const char *xml,
                                      const char *cmdline)
 {
-    char *actualargv = NULL;
+    g_autofree char *actualargv = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     GHashTable *vars = virHashNew(virNWFilterVarValueHashFree);
     virNWFilterInst inst;
@@ -382,7 +381,6 @@ static int testCompareXMLToArgvFiles(const char *xml,
     ret = 0;
 
  cleanup:
-    VIR_FREE(actualargv);
     virNWFilterInstReset(&inst);
     virHashFree(vars);
     return ret;
@@ -398,8 +396,8 @@ testCompareXMLToIPTablesHelper(const void *data)
 {
     int result = -1;
     const struct testInfo *info = data;
-    char *xml = NULL;
-    char *args = NULL;
+    g_autofree char *xml = NULL;
+    g_autofree char *args = NULL;
 
     xml = g_strdup_printf("%s/nwfilterxml2firewalldata/%s.xml",
                           abs_srcdir, info->name);
@@ -408,8 +406,6 @@ testCompareXMLToIPTablesHelper(const void *data)
 
     result = testCompareXMLToArgvFiles(xml, args);
 
-    VIR_FREE(xml);
-    VIR_FREE(args);
     return result;
 }
 
diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c
index 82ce042e01..7a7e05965b 100644
--- a/tests/nwfilterxml2xmltest.c
+++ b/tests/nwfilterxml2xmltest.c
@@ -20,7 +20,7 @@ static int
 testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
                          bool expect_error)
 {
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
     virNWFilterDef *dev = NULL;
 
@@ -44,7 +44,6 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
     ret = 0;
 
  fail:
-    VIR_FREE(actual);
     virNWFilterDefFree(dev);
     return ret;
 }
@@ -59,17 +58,14 @@ testCompareXMLToXMLHelper(const void *data)
 {
     int result = -1;
     const test_parms *tp = data;
-    char *inxml = NULL;
-    char *outxml = NULL;
+    g_autofree char *inxml = NULL;
+    g_autofree char *outxml = NULL;
 
     inxml = g_strdup_printf("%s/nwfilterxml2xmlin/%s.xml", abs_srcdir, tp->name);
     outxml = g_strdup_printf("%s/nwfilterxml2xmlout/%s.xml", abs_srcdir, tp->name);
 
     result = testCompareXMLToXMLFiles(inxml, outxml, tp->expect_warning);
 
-    VIR_FREE(inxml);
-    VIR_FREE(outxml);
-
     return result;
 }
 
-- 
2.31.1




[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]

  Powered by Linux