Perform the object initialization in a helper rather than inline
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/virnwfilterobj.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index 9846751..dcfd1e7 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -43,6 +43,26 @@ struct _virNWFilterObj {
};
+static virNWFilterObjPtr
+virNWFilterObjNew(void)
+{
+ virNWFilterObjPtr obj;
+
+ if (VIR_ALLOC(obj) < 0)
+ return NULL;
+
+ if (virMutexInitRecursive(&obj->lock) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("cannot initialize mutex"));
+ VIR_FREE(obj);
+ return NULL;
+ }
+
+ virNWFilterObjLock(obj);
+ return obj;
+}
+
+
virNWFilterDefPtr
virNWFilterObjGetDef(virNWFilterObjPtr obj)
{
@@ -328,16 +348,8 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
return obj;
}
- if (VIR_ALLOC(obj) < 0)
- return NULL;
-
- if (virMutexInitRecursive(&obj->lock) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("cannot initialize mutex"));
- VIR_FREE(obj);
+ if (!(obj = virNWFilterObjNew()))
return NULL;
- }
- virNWFilterObjLock(obj);
if (VIR_APPEND_ELEMENT_COPY(nwfilters->objs,
nwfilters->count, obj) < 0) {
--
2.9.3