]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Convert virDomainChrSourceDefNew to return object
authorJohn Ferlan <jferlan@redhat.com>
Fri, 6 Apr 2018 16:05:38 +0000 (12:05 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 10 Apr 2018 12:11:09 +0000 (08:11 -0400)
Let's use object referencing to handle the ChrSourceDef. A subsequent
patch then can allow the monConfig to take an extra reference before
dropping the domain lock to then ensure nothing free's the memory that
needs to be used.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
src/conf/domain_conf.c

index fd57364cd4248805176738eb647f60e8be3ab99c..d23182f18a47778a1fad1f637c896331bfc41a2c 100644 (file)
@@ -2260,8 +2260,10 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest,
     return 0;
 }
 
-void virDomainChrSourceDefFree(virDomainChrSourceDefPtr def)
+static void
+virDomainChrSourceDefDispose(void *obj)
 {
+    virDomainChrSourceDefPtr def = obj;
     size_t i;
 
     if (!def)
@@ -2275,11 +2277,16 @@ void virDomainChrSourceDefFree(virDomainChrSourceDefPtr def)
             virSecurityDeviceLabelDefFree(def->seclabels[i]);
         VIR_FREE(def->seclabels);
     }
+}
 
 
-    VIR_FREE(def);
+void
+virDomainChrSourceDefFree(virDomainChrSourceDefPtr def)
+{
+    virObjectUnref(def);
 }
 
+
 /* virDomainChrSourceDefIsEqual:
  * @src: Source
  * @tgt: Target
@@ -12211,17 +12218,39 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
 }
 
 
+static virClassPtr virDomainChrSourceDefClass;
+
+static int
+virDomainChrSourceDefOnceInit(void)
+{
+    virDomainChrSourceDefClass = virClassNew(virClassForObject(),
+                                             "virDomainChrSourceDef",
+                                             sizeof(virDomainChrSourceDef),
+                                             virDomainChrSourceDefDispose);
+    if (!virDomainChrSourceDefClass)
+        return -1;
+    else
+        return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virDomainChrSourceDef);
+
 virDomainChrSourceDefPtr
 virDomainChrSourceDefNew(virDomainXMLOptionPtr xmlopt)
 {
     virDomainChrSourceDefPtr def = NULL;
 
-    if (VIR_ALLOC(def) < 0)
+    if (virDomainChrSourceDefInitialize() < 0)
+        return NULL;
+
+    if (!(def = virObjectNew(virDomainChrSourceDefClass)))
         return NULL;
 
     if (xmlopt && xmlopt->privateData.chrSourceNew &&
-        !(def->privateData = xmlopt->privateData.chrSourceNew()))
-        VIR_FREE(def);
+        !(def->privateData = xmlopt->privateData.chrSourceNew())) {
+        virObjectUnref(def);
+        def = NULL;
+    }
 
     return def;
 }