Use automatic memory freeing and modern XML parsers to simplify the
function.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/nwfilter_conf.c | 26 +++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index f96ae707f9..b79fd2561e 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -298,7 +298,7 @@ virNWFilterIncludeDefFree(virNWFilterIncludeDef *inc)
g_free(inc->filterref);
g_free(inc);
}
-
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNWFilterIncludeDef, virNWFilterIncludeDefFree);
static void
virNWFilterEntryFree(virNWFilterEntry *entry)
@@ -2031,27 +2031,15 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
static virNWFilterIncludeDef *
virNWFilterIncludeParse(xmlNodePtr cur)
{
- virNWFilterIncludeDef *ret;
-
- ret = g_new0(virNWFilterIncludeDef, 1);
-
- ret->filterref = virXMLPropString(cur, "filter");
- if (!ret->filterref) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s",
- _("rule node requires action attribute"));
- goto err_exit;
- }
+ g_autoptr(virNWFilterIncludeDef) ret = g_new0(virNWFilterIncludeDef, 1);
- ret->params = virNWFilterParseParamAttributes(cur);
- if (!ret->params)
- goto err_exit;
+ if (!(ret->filterref = virXMLPropStringRequired(cur, "filter")))
+ return NULL;
- return ret;
+ if (!(ret->params = virNWFilterParseParamAttributes(cur)))
+ return NULL;
- err_exit:
- virNWFilterIncludeDefFree(ret);
- return NULL;
+ return g_steal_pointer(&ret);
}
--
2.40.1