[libvirt] [PATCH 06/15] nwfilter: Introduce virNWFilterObjNew

John Ferlan jferlan at redhat.com
Mon Apr 24 19:18:35 UTC 2017


Perform the object initialization in a helper rather than inline

Signed-off-by: John Ferlan <jferlan at 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




More information about the libvir-list mailing list