gst/gstutils.c: Don't leak pad references.
authorJan Schmidt <thaytan@mad.scientist.com>
Sat, 28 Jan 2006 00:59:37 +0000 (00:59 +0000)
committerJan Schmidt <thaytan@mad.scientist.com>
Sat, 28 Jan 2006 00:59:37 +0000 (00:59 +0000)
Original commit message from CVS:
* gst/gstutils.c: (gst_element_unlink_pads):
Don't leak pad references.

* tests/check/elements/fakesink.c: (GST_START_TEST):
* tests/check/generic/sinks.c: (GST_START_TEST):
* tests/check/generic/states.c: (GST_START_TEST):
* tests/check/gst/gstbin.c: (GST_START_TEST):
* tests/check/gst/gstcaps.c: (GST_START_TEST):
* tests/check/gst/gstelement.c: (GST_START_TEST):
* tests/check/gst/gstghostpad.c: (GST_START_TEST):
* tests/check/gst/gstiterator.c: (GST_START_TEST):
* tests/check/gst/gstvalue.c: (GST_START_TEST):
Fix a bunch of leaks. Make generic/sinks.c
use a bit less cpu by slowing the buffer rate
between fakesrc and fakesink.

gst/gstutils.c
tests/check/elements/fakesink.c
tests/check/generic/sinks.c
tests/check/generic/states.c
tests/check/gst/gstbin.c
tests/check/gst/gstcaps.c
tests/check/gst/gstelement.c
tests/check/gst/gstghostpad.c
tests/check/gst/gstiterator.c
tests/check/gst/gstvalue.c

index d91353d..8191d9f 100644 (file)
@@ -1710,14 +1710,17 @@ gst_element_unlink_pads (GstElement * src, const gchar * srcpadname,
     return;
   }
   destpad = gst_element_get_pad (dest, destpadname);
-  if (srcpad == NULL) {
+  if (destpad == NULL) {
     GST_WARNING_OBJECT (dest, "destination element has no pad \"%s\"",
         destpadname);
+    gst_object_unref (srcpad);
     return;
   }
 
   /* we're satisified they can be unlinked, let's do it */
   gst_pad_unlink (srcpad, destpad);
+  gst_object_unref (srcpad);
+  gst_object_unref (destpad);
 }
 
 /**
index 382b791..a96dce0 100644 (file)
@@ -208,6 +208,11 @@ GST_START_TEST (test_clipping)
     fret = gst_pad_chain (sinkpad, buffer);
     fail_if (fret != GST_FLOW_OK);
   }
+
+  gst_element_set_state (sink, GST_STATE_NULL);
+  gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
+  gst_object_unref (sinkpad);
+  gst_object_unref (sink);
 }
 
 GST_END_TEST;
index 1fb292b..8a078ea 100644 (file)
@@ -86,6 +86,7 @@ GST_START_TEST (test_sink_completion)
   GstState current, pending;
 
   sink = gst_element_factory_make ("fakesink", "sink");
+  g_object_set (G_OBJECT (sink), "sync", TRUE, NULL);
 
   ret = gst_element_set_state (sink, GST_STATE_PLAYING);
   fail_unless (ret == GST_STATE_CHANGE_ASYNC, "no async state return");
@@ -96,6 +97,7 @@ GST_START_TEST (test_sink_completion)
   fail_unless (pending == GST_STATE_PLAYING, "bad pending state");
 
   src = gst_element_factory_make ("fakesrc", "src");
+  g_object_set (G_OBJECT (src), "datarate", 200, "sizetype", 2, NULL);
   gst_element_link (src, sink);
 
   ret = gst_element_set_state (src, GST_STATE_PLAYING);
@@ -200,6 +202,8 @@ GST_START_TEST (test_livesrc_remove)
   fail_unless (ret == GST_STATE_CHANGE_ASYNC, "not async");
   fail_unless (current == GST_STATE_PAUSED, "not paused");
   fail_unless (pending == GST_STATE_PAUSED, "not paused");
+
+  gst_object_unref (pipeline);
 }
 
 GST_END_TEST
index ac1faea..56fd38f 100644 (file)
@@ -54,6 +54,7 @@ GST_START_TEST (test_state_changes)
 
     gst_object_unref (GST_OBJECT (element));
   }
+  gst_plugin_feature_list_free (features);
   gst_task_cleanup_all ();
 }
 
index a71a4d8..e006295 100644 (file)
@@ -57,10 +57,13 @@ GST_START_TEST (test_interface)
   gst_bin_add (bin, filesrc);
 
   fail_unless (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
+  gst_object_unref (filesrc);
+
   it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
   fail_unless (it != NULL);
   fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
   fail_unless (item == (gpointer) filesrc);
+  gst_object_unref (GST_OBJECT (item));
   fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
   gst_iterator_free (it);
 
@@ -68,11 +71,11 @@ GST_START_TEST (test_interface)
       gst_element_factory_make ("identity", NULL),
       gst_element_factory_make ("identity", NULL),
       gst_element_factory_make ("identity", NULL), NULL);
-  fail_unless (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
   it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
   fail_unless (it != NULL);
   fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
   fail_unless (item == (gpointer) filesrc);
+  gst_object_unref (GST_OBJECT (item));
   fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
   gst_iterator_free (it);
 
@@ -83,10 +86,10 @@ GST_START_TEST (test_interface)
       gst_element_factory_make ("identity", NULL),
       gst_element_factory_make ("identity", NULL),
       GST_ELEMENT (bin2), gst_element_factory_make ("identity", NULL), NULL);
-  fail_unless (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
   it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
   fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
   fail_unless (item == (gpointer) filesrc);
+  gst_object_unref (GST_OBJECT (item));
   fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
   gst_iterator_free (it);
 
@@ -94,8 +97,11 @@ GST_START_TEST (test_interface)
   gst_bin_add (bin2, gst_element_factory_make ("filesrc", NULL));
   it = gst_bin_iterate_all_by_interface (bin, GST_TYPE_URI_HANDLER);
   fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
+  gst_object_unref (GST_OBJECT (item));
   fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
+  gst_object_unref (GST_OBJECT (item));
   fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_OK);
+  gst_object_unref (GST_OBJECT (item));
   fail_unless (gst_iterator_next (it, &item) == GST_ITERATOR_DONE);
   gst_iterator_free (it);
 
index b31da8d..ca00ae9 100644 (file)
@@ -43,8 +43,8 @@ GST_START_TEST (test_from_string)
 
     fail_unless (gst_caps_is_equal (caps, caps2));
 
-    g_free (caps);
-    g_free (caps2);
+    gst_caps_unref (caps);
+    gst_caps_unref (caps2);
     g_free (to_str);
   }
 }
@@ -61,9 +61,13 @@ GST_START_TEST (test_buffer)
       "buffer", GST_TYPE_BUFFER, buffer, NULL);
 
   GST_DEBUG ("caps: %" GST_PTR_FORMAT, c1);
-
-  gst_buffer_set_caps (buffer, c1);     /* gives away our c1 ref */
   gst_buffer_unref (buffer);
+
+  buffer = gst_buffer_new_and_alloc (1000);
+  gst_buffer_set_caps (buffer, c1);     /* doesn't give away our c1 ref */
+
+  gst_caps_unref (c1);
+  gst_buffer_unref (buffer);    /* Should now drop both references */
 }
 
 GST_END_TEST;
@@ -115,7 +119,7 @@ GST_END_TEST;
 
 GST_START_TEST (test_static_caps)
 {
-  GstStaticCaps scaps = GST_STATIC_CAPS ("audio/x-raw-int,rate=44100");
+  static GstStaticCaps scaps = GST_STATIC_CAPS ("audio/x-raw-int,rate=44100");
   GstCaps *caps1;
   GstCaps *caps2;
 
index 10c1536..7c8558a 100644 (file)
@@ -45,6 +45,7 @@ GST_START_TEST (test_add_remove_pad)
 
   /* clean up our own reference */
   gst_object_unref (p);
+  gst_object_unref (e);
 }
 
 GST_END_TEST;
@@ -127,11 +128,17 @@ GST_START_TEST (test_link)
   gst_element_set_state (sink, GST_STATE_NULL);
   gst_element_set_state (src, GST_STATE_NULL);
 
+  gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
+  g_usleep (G_USEC_PER_SEC / 2);
+
   ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
   ASSERT_OBJECT_REFCOUNT (src, "src", 1);
   gst_element_unlink_pads (src, "src", sink, "sink");
   ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
   ASSERT_OBJECT_REFCOUNT (src, "src", 1);
+
+  gst_object_unref (src);
+  gst_object_unref (sink);
 }
 
 GST_END_TEST;
index 6dec901..1d6c385 100644 (file)
@@ -58,6 +58,8 @@ GST_START_TEST (test_remove1)
   srcpad = gst_element_get_pad (src, "src");
   /* pad cannot be linked now */
   fail_if (gst_pad_is_linked (srcpad));
+
+  gst_object_unref (b1);
 }
 
 GST_END_TEST;
index 369d39c..720114b 100644 (file)
@@ -70,6 +70,7 @@ GST_START_TEST (test_manual_iteration)
   /* clean up */
   gst_iterator_free (iter);
   g_mutex_free (m);
+  g_list_free (l);
 }
 
 GST_END_TEST;
@@ -119,6 +120,7 @@ GST_START_TEST (test_resync)
   /* clean up */
   gst_iterator_free (iter);
   g_mutex_free (m);
+  g_list_free (l);
 }
 
 GST_END_TEST;
@@ -160,6 +162,7 @@ GST_START_TEST (test_fold)
   /* clean up */
   gst_iterator_free (iter);
   g_mutex_free (m);
+  g_list_free (l);
 }
 
 GST_END_TEST;
index 32992dc..aa416a9 100644 (file)
@@ -472,6 +472,9 @@ GST_START_TEST (test_value_intersect)
   fail_unless (GST_VALUE_HOLDS_FOURCC (&dest));
   fail_unless (gst_value_get_fourcc (&dest) ==
       GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'));
+
+  g_value_unset (&src1);
+  g_value_unset (&src2);
 }
 
 GST_END_TEST;