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(a)redhat.com>
---
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