mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
virNWFilterIncludeDefToRuleInst: Refactor cleanup
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@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
abd045030e
commit
0b6888451f
@ -281,20 +281,20 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverState *driver,
|
|||||||
virNWFilterInst *inst)
|
virNWFilterInst *inst)
|
||||||
{
|
{
|
||||||
virNWFilterObj *obj;
|
virNWFilterObj *obj;
|
||||||
GHashTable *tmpvars = NULL;
|
g_autoptr(GHashTable) tmpvars = NULL;
|
||||||
virNWFilterDef *childdef;
|
virNWFilterDef *childdef;
|
||||||
virNWFilterDef *newChilddef;
|
virNWFilterDef *newChilddef;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
VIR_DEBUG("Instantiating filter %s", inc->filterref);
|
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 */
|
/* create a temporary hashmap for depth-first tree traversal */
|
||||||
if (!(tmpvars = virNWFilterCreateVarsFrom(inc->params,
|
if (!(tmpvars = virNWFilterCreateVarsFrom(inc->params, vars)))
|
||||||
vars)))
|
return -1;
|
||||||
goto cleanup;
|
|
||||||
|
/* '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);
|
childdef = virNWFilterObjGetDef(obj);
|
||||||
|
|
||||||
@ -311,24 +311,18 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverState *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
VIR_APPEND_ELEMENT(inst->filters, inst->nfilters, obj);
|
VIR_APPEND_ELEMENT(inst->filters, inst->nfilters, obj);
|
||||||
obj = NULL;
|
|
||||||
|
|
||||||
if (virNWFilterDefToInst(driver,
|
if (virNWFilterDefToInst(driver,
|
||||||
childdef,
|
childdef,
|
||||||
tmpvars,
|
tmpvars,
|
||||||
useNewFilter,
|
useNewFilter,
|
||||||
foundNewFilter,
|
foundNewFilter,
|
||||||
inst) < 0)
|
inst) < 0) {
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
cleanup:
|
|
||||||
if (ret < 0)
|
|
||||||
virNWFilterInstReset(inst);
|
virNWFilterInstReset(inst);
|
||||||
virHashFree(tmpvars);
|
return -1;
|
||||||
if (obj)
|
}
|
||||||
virNWFilterObjUnlock(obj);
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user