conf: nwfilter: Refactor virNWFilterIncludeParse

Use automatic memory freeing and modern XML parsers to simplify the
function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-04-11 18:02:28 +02:00
parent 9cb4e78ffd
commit 3a5f9a4041

View File

@ -298,7 +298,7 @@ virNWFilterIncludeDefFree(virNWFilterIncludeDef *inc)
g_free(inc->filterref); g_free(inc->filterref);
g_free(inc); g_free(inc);
} }
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNWFilterIncludeDef, virNWFilterIncludeDefFree);
static void static void
virNWFilterEntryFree(virNWFilterEntry *entry) virNWFilterEntryFree(virNWFilterEntry *entry)
@ -2031,27 +2031,15 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
static virNWFilterIncludeDef * static virNWFilterIncludeDef *
virNWFilterIncludeParse(xmlNodePtr cur) virNWFilterIncludeParse(xmlNodePtr cur)
{ {
virNWFilterIncludeDef *ret; g_autoptr(virNWFilterIncludeDef) ret = g_new0(virNWFilterIncludeDef, 1);
ret = g_new0(virNWFilterIncludeDef, 1); if (!(ret->filterref = virXMLPropStringRequired(cur, "filter")))
ret->filterref = virXMLPropString(cur, "filter");
if (!ret->filterref) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s",
_("rule node requires action attribute"));
goto err_exit;
}
ret->params = virNWFilterParseParamAttributes(cur);
if (!ret->params)
goto err_exit;
return ret;
err_exit:
virNWFilterIncludeDefFree(ret);
return NULL; return NULL;
if (!(ret->params = virNWFilterParseParamAttributes(cur)))
return NULL;
return g_steal_pointer(&ret);
} }