[PATCH 16/23] virNWFilterRuleDefToRuleInst: Restructure code to avoid cleanup

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

 



Construct the 'ruleinst->vars' hash table separately in a temporary
variable so that 'ruleinst' can be allocated on success. This allows us
to get rid of the cleanup section.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/nwfilter/nwfilter_gentech_driver.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 4ea0f6f0d6..c9ffa30839 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -252,8 +252,11 @@ virNWFilterRuleDefToRuleInst(virNWFilterDef *def,
                              GHashTable *vars,
                              virNWFilterInst *inst)
 {
+    g_autoptr(GHashTable) tmpvars = virHashNew(virNWFilterVarValueHashFree);
     virNWFilterRuleInst *ruleinst;
-    int ret = -1;
+
+    if (virNWFilterHashTablePutAll(vars, tmpvars) < 0)
+        return -1;

     ruleinst = g_new0(virNWFilterRuleInst, 1);

@@ -261,17 +264,11 @@ virNWFilterRuleDefToRuleInst(virNWFilterDef *def,
     ruleinst->chainPriority = def->chainPriority;
     ruleinst->def = rule;
     ruleinst->priority = rule->priority;
-    ruleinst->vars = virHashNew(virNWFilterVarValueHashFree);
-
-    if (virNWFilterHashTablePutAll(vars, ruleinst->vars) < 0)
-        goto cleanup;
+    ruleinst->vars = g_steal_pointer(&tmpvars);

     VIR_APPEND_ELEMENT(inst->rules, inst->nrules, ruleinst);

-    ret = 0;
- cleanup:
-    virNWFilterRuleInstFree(ruleinst);
-    return ret;
+    return 0;
 }


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