fix memory leaks
authorJoshua N. Pritikin <vishnu@pobox.com>
Thu, 13 Sep 2001 20:12:17 +0000 (20:12 +0000)
committerJoshua N. Pritikin <vishnu@pobox.com>
Thu, 13 Sep 2001 20:12:17 +0000 (20:12 +0000)
Original commit message from CVS:
fix memory leaks

gst/gstelement.c
gst/gstelement.h
gst/gstelementfactory.c
gst/gstpad.c

index 388c139..a29ba30 100644 (file)
@@ -1113,9 +1113,9 @@ gst_element_restore_thyself (xmlNodePtr self, GstObject *parent)
   // first get the needed tags to construct the element
   while (children) {
     if (!strcmp (children->name, "name")) {
-      name = g_strdup (xmlNodeGetContent (children));
+      name = xmlNodeGetContent (children);
     } else if (!strcmp (children->name, "type")) {
-      type = g_strdup (xmlNodeGetContent (children));
+      type = xmlNodeGetContent (children);
     }
     children = children->next;
   }
@@ -1142,10 +1142,10 @@ gst_element_restore_thyself (xmlNodePtr self, GstObject *parent)
 
       while (child) {
         if (!strcmp (child->name, "name")) {
-          name = g_strdup (xmlNodeGetContent (child));
+          name = xmlNodeGetContent (child);
        }
        else if (!strcmp (child->name, "value")) {
-          value = g_strdup (xmlNodeGetContent (child));
+          value = xmlNodeGetContent (child);
        }
         child = child->next;
       }
index 31eaf43..a45c91a 100644 (file)
@@ -262,6 +262,8 @@ struct _GstElementFactory {
 
   GType type;                  /* unique GType of element */
 
+  guint details_dynamic : 1;
+
   GstElementDetails *details;  /* pointer to details struct */
 
   GList *padtemplates;
index 1fdc911..546a203 100644 (file)
@@ -138,6 +138,25 @@ gst_elementfactory_get_list (void)
   return _gst_elementfactories;
 }
 
+static void
+gst_element_details_free (GstElementDetails *dp)
+{
+  g_return_if_fail (dp);
+
+  if (dp->longname)
+    g_free (dp->longname);
+  if (dp->klass)
+    g_free (dp->klass);
+  if (dp->description)
+    g_free (dp->description);
+  if (dp->version)
+    g_free (dp->version);
+  if (dp->author)
+    g_free (dp->author);
+  if (dp->copyright)
+    g_free (dp->copyright);
+  g_free (dp);
+}
 
 /**
  * gst_elementfactory_new:
@@ -158,29 +177,27 @@ gst_elementfactory_new (const gchar *name, GType type,
 
   g_return_val_if_fail(name != NULL, NULL);
   g_return_val_if_fail(type != 0, NULL);
+  g_return_val_if_fail (details, NULL);
 
   factory = gst_elementfactory_find (name);
 
-  if (factory)
-    {
-      if (!type)
-       g_warning ("gst_elementfactory_new for `%s' still didn't set type",
-                  name);
+  if (!factory)
+    factory = GST_ELEMENTFACTORY (g_object_new (GST_TYPE_ELEMENTFACTORY, NULL));
 
-      if (!factory->type)
-       factory->type = type;
-      else if (factory->type != type)
-       g_critical ("%s type changed", name);
-
-      return factory;
+  if (factory->details_dynamic)
+    {
+      gst_element_details_free (factory->details);
+      factory->details_dynamic = FALSE;
     }
 
-  // probably created by the registry
-  factory = GST_ELEMENTFACTORY (g_object_new (GST_TYPE_ELEMENTFACTORY, NULL));
+  factory->details = details;
+
+  if (!factory->type)
+    factory->type = type;
+  else if (factory->type != type)
+    g_critical ("`%s' requested type change (!)", name);
 
   gst_object_set_name (GST_OBJECT (factory), name);
-  factory->type = type;
-  factory->details = details;
 
   return factory;
 }
@@ -400,12 +417,18 @@ gst_elementfactory_save_thyself (GstObject *object,
 
   g_return_val_if_fail(factory != NULL, NULL);
 
-  xmlNewChild(parent,NULL,"longname", factory->details->longname);
-  xmlNewChild(parent,NULL,"class", factory->details->klass);
-  xmlNewChild(parent,NULL,"description", factory->details->description);
-  xmlNewChild(parent,NULL,"version", factory->details->version);
-  xmlNewChild(parent,NULL,"author", factory->details->author);
-  xmlNewChild(parent,NULL,"copyright", factory->details->copyright);
+  if (factory->details)
+    {
+      xmlNewChild(parent,NULL,"longname", factory->details->longname);
+      xmlNewChild(parent,NULL,"class", factory->details->klass);
+      xmlNewChild(parent,NULL,"description", factory->details->description);
+      xmlNewChild(parent,NULL,"version", factory->details->version);
+      xmlNewChild(parent,NULL,"author", factory->details->author);
+      xmlNewChild(parent,NULL,"copyright", factory->details->copyright);
+    }
+  else
+    g_warning ("elementfactory `%s' is missing details",
+              object->name);
 
   pads = factory->padtemplates;
   if (pads) {
@@ -427,6 +450,8 @@ gst_elementfactory_restore_thyself (GstObject *object, xmlNodePtr parent)
 {
   GstElementFactory *factory = GST_ELEMENTFACTORY (object);
   xmlNodePtr children = parent->xmlChildrenNode;
+  
+  factory->details_dynamic = TRUE;
   factory->details = g_new0(GstElementDetails, 1);
   factory->padtemplates = NULL;
 
index 8bd351c..5f1d7d7 100644 (file)
@@ -1059,7 +1059,7 @@ gst_pad_load_and_connect (xmlNodePtr self,
       pad = gst_element_get_pad (GST_ELEMENT (parent), xmlNodeGetContent (field));
     }
     else if (!strcmp(field->name, "peer")) {
-      peer = g_strdup (xmlNodeGetContent (field));
+      peer = xmlNodeGetContent (field);
     }
     field = field->next;
   }