mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
virNWFilterRuleDefToRuleInst: Restructure code to avoid cleanup
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@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
8d4468d007
commit
abd045030e
@ -252,8 +252,11 @@ virNWFilterRuleDefToRuleInst(virNWFilterDef *def,
|
|||||||
GHashTable *vars,
|
GHashTable *vars,
|
||||||
virNWFilterInst *inst)
|
virNWFilterInst *inst)
|
||||||
{
|
{
|
||||||
|
g_autoptr(GHashTable) tmpvars = virHashNew(virNWFilterVarValueHashFree);
|
||||||
virNWFilterRuleInst *ruleinst;
|
virNWFilterRuleInst *ruleinst;
|
||||||
int ret = -1;
|
|
||||||
|
if (virNWFilterHashTablePutAll(vars, tmpvars) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
ruleinst = g_new0(virNWFilterRuleInst, 1);
|
ruleinst = g_new0(virNWFilterRuleInst, 1);
|
||||||
|
|
||||||
@ -261,17 +264,11 @@ virNWFilterRuleDefToRuleInst(virNWFilterDef *def,
|
|||||||
ruleinst->chainPriority = def->chainPriority;
|
ruleinst->chainPriority = def->chainPriority;
|
||||||
ruleinst->def = rule;
|
ruleinst->def = rule;
|
||||||
ruleinst->priority = rule->priority;
|
ruleinst->priority = rule->priority;
|
||||||
ruleinst->vars = virHashNew(virNWFilterVarValueHashFree);
|
ruleinst->vars = g_steal_pointer(&tmpvars);
|
||||||
|
|
||||||
if (virNWFilterHashTablePutAll(vars, ruleinst->vars) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
VIR_APPEND_ELEMENT(inst->rules, inst->nrules, ruleinst);
|
VIR_APPEND_ELEMENT(inst->rules, inst->nrules, ruleinst);
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
virNWFilterRuleInstFree(ruleinst);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user