Use automatic memory freeing for 'tmpvars' and move the allocation of
tmpvars earlier so that we are guaranteed that 'obj' will always be
appended to 'inst->filters' and thus don't need cleanup for it.
By moving the reset of 'inst' to the block when virNWFilterDefToInst
fails we can get rid of the rest of the cleanup section and remove the
'ret' variable.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/nwfilter/nwfilter_gentech_driver.c | 32 +++++++++++---------------
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/src/nwfilter/nwfilter_gentech_driver.c
b/src/nwfilter/nwfilter_gentech_driver.c
index c9ffa30839..ecba16d55c 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -281,20 +281,20 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverState *driver,
virNWFilterInst *inst)
{
virNWFilterObj *obj;
- GHashTable *tmpvars = NULL;
+ g_autoptr(GHashTable) tmpvars = NULL;
virNWFilterDef *childdef;
virNWFilterDef *newChilddef;
- int ret = -1;
VIR_DEBUG("Instantiating filter %s", inc->filterref);
- if (!(obj = virNWFilterObjListFindInstantiateFilter(driver->nwfilters,
- inc->filterref)))
- goto cleanup;
/* create a temporary hashmap for depth-first tree traversal */
- if (!(tmpvars = virNWFilterCreateVarsFrom(inc->params,
- vars)))
- goto cleanup;
+ if (!(tmpvars = virNWFilterCreateVarsFrom(inc->params, vars)))
+ return -1;
+
+ /* 'obj' is always appended to 'inst->filters' thus we don't
unlock it */
+ if (!(obj = virNWFilterObjListFindInstantiateFilter(driver->nwfilters,
+ inc->filterref)))
+ return -1;
childdef = virNWFilterObjGetDef(obj);
@@ -311,24 +311,18 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverState *driver,
}
VIR_APPEND_ELEMENT(inst->filters, inst->nfilters, obj);
- obj = NULL;
if (virNWFilterDefToInst(driver,
childdef,
tmpvars,
useNewFilter,
foundNewFilter,
- inst) < 0)
- goto cleanup;
-
- ret = 0;
- cleanup:
- if (ret < 0)
+ inst) < 0) {
virNWFilterInstReset(inst);
- virHashFree(tmpvars);
- if (obj)
- virNWFilterObjUnlock(obj);
- return ret;
+ return -1;
+ }
+
+ return 0;
}
--
2.31.1