[PATCH v2 06/13] nwfilter: Introduce virNWFilterObjNew

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Perform the object initialization in a helper rather than inline

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 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 77d5c1e..7c21327 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)
 {
@@ -321,16 +341,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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux