gst/gstxml.c: Chain up to parent class in dispose function and also unref the elements in the toplevel_elements GList.
Original commit message from CVS:
* gst/gstxml.c: (gst_xml_dispose), (gst_xml_parse_file),
(gst_xml_parse_memory), (gst_xml_get_element):
Chain up to parent class in dispose function and also
unref the elements in the toplevel_elements GList.
Don't leak XmlDocPtr in _parse_file() and _parse_memory().
Always return a reference in gst_xml_get_element() rather
than only sometimes.
* tools/gst-launch.c: (xmllaunch_parse_cmdline):
Don't leak GstXml object.
diff --git a/ChangeLog b/ChangeLog
index 9cace96..d8c619d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2006-08-21 Tim-Philipp Müller <tim at centricular dot net>
+
+ * gst/gstxml.c: (gst_xml_dispose), (gst_xml_parse_file),
+ (gst_xml_parse_memory), (gst_xml_get_element):
+ Chain up to parent class in dispose function and also
+ unref the elements in the toplevel_elements GList.
+ Don't leak XmlDocPtr in _parse_file() and _parse_memory().
+ Always return a reference in gst_xml_get_element() rather
+ than only sometimes.
+
+ * tools/gst-launch.c: (xmllaunch_parse_cmdline):
+ Don't leak GstXml object.
+
2006-08-21 Stefan Kost <ensonic@users.sf.net>
* docs/gst/gstreamer-sections.txt:
diff --git a/gst/gstxml.c b/gst/gstxml.c
index 63529a8..d6462c9 100644
--- a/gst/gstxml.c
+++ b/gst/gstxml.c
@@ -120,7 +120,13 @@
static void
gst_xml_dispose (GObject * object)
{
- g_list_free (GST_XML (object)->topelements);
+ GstXML *xml = GST_XML (object);
+
+ g_list_foreach (xml->topelements, (GFunc) gst_object_unref, NULL);
+ g_list_free (xml->topelements);
+ xml->topelements = NULL;
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
}
/**
@@ -309,6 +315,7 @@
gst_xml_parse_file (GstXML * xml, const guchar * fname, const guchar * root)
{
xmlDocPtr doc;
+ gboolean ret;
g_return_val_if_fail (fname != NULL, FALSE);
@@ -319,7 +326,10 @@
return FALSE;
}
- return gst_xml_parse_doc (xml, doc, root);
+ ret = gst_xml_parse_doc (xml, doc, root);
+
+ xmlFreeDoc (doc);
+ return ret;
}
/* FIXME 0.9: guchar* */
@@ -340,12 +350,16 @@
const gchar * root)
{
xmlDocPtr doc;
+ gboolean ret;
g_return_val_if_fail (buffer != NULL, FALSE);
doc = xmlParseMemory ((char *) buffer, size);
- return gst_xml_parse_doc (xml, doc, (const xmlChar *) root);
+ ret = gst_xml_parse_doc (xml, doc, (const xmlChar *) root);
+
+ xmlFreeDoc (doc);
+ return ret;
}
static void
@@ -375,7 +389,7 @@
return xml->topelements;
}
-/* FIXME 0.9: why is the arg guchar* instead of gchar*? */
+/* FIXME 0.11: why is the arg guchar* instead of gchar*? */
/**
* gst_xml_get_element:
* @xml: The GstXML to get the element from
@@ -385,7 +399,7 @@
* to name in the pipeline description. You would use this if you have
* to do anything to the element after loading.
*
- * Returns: a pointer to a new GstElement
+ * Returns: a pointer to a new GstElement, caller owns returned reference.
*/
GstElement *
gst_xml_get_element (GstXML * xml, const guchar * name)
@@ -405,7 +419,7 @@
GST_DEBUG ("gstxml: getting element \"%s\"", name);
if (!strcmp (GST_ELEMENT_NAME (top), (char *) name)) {
- return top;
+ return GST_ELEMENT_CAST (gst_object_ref (top));
} else {
if (GST_IS_BIN (top)) {
element = gst_bin_get_by_name (GST_BIN (top), (gchar *) name);
diff --git a/tools/gst-launch.c b/tools/gst-launch.c
index 80771a5..fde6b0c 100644
--- a/tools/gst-launch.c
+++ b/tools/gst-launch.c
@@ -129,8 +129,10 @@
if (!l)
return NULL;
- else
- return l->data;
+
+ gst_object_ref (pipeline);
+ gst_object_unref (xml);
+ return pipeline;
}
#endif