rtsp-stream: fixed valgrind error
authorSrimanta Panda <srimanta@axis.com>
Tue, 8 Dec 2015 07:27:20 +0000 (08:27 +0100)
committerSebastian Dröge <sebastian@centricular.com>
Tue, 8 Dec 2015 07:47:53 +0000 (09:47 +0200)
Fixed the valgrind error in unit test. The UDP source created during
gst_rtsp_stream_join_bin() was not released while destroying the rtp
bin.

https://bugzilla.gnome.org/show_bug.cgi?id=759010

gst/rtsp-server/rtsp-stream.c

index b775689..f329911 100644 (file)
@@ -2484,18 +2484,31 @@ gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin,
       gst_element_set_state (priv->funnel[i], GST_STATE_NULL);
     if (priv->appsrc[i])
       gst_element_set_state (priv->appsrc[i], GST_STATE_NULL);
-    if (priv->udpsrc_v4[i] && (priv->sinkpad || i == 1)) {
-      /* and set udpsrc to NULL now before removing */
-      gst_element_set_locked_state (priv->udpsrc_v4[i], FALSE);
-      gst_element_set_state (priv->udpsrc_v4[i], GST_STATE_NULL);
-      /* removing them should also nicely release the request
-       * pads when they finalize */
-      gst_bin_remove (bin, priv->udpsrc_v4[i]);
+
+    if (priv->udpsrc_v4[i]) {
+      if (priv->sinkpad || i == 1) {
+        /* and set udpsrc to NULL now before removing */
+        gst_element_set_locked_state (priv->udpsrc_v4[i], FALSE);
+        gst_element_set_state (priv->udpsrc_v4[i], GST_STATE_NULL);
+        /* removing them should also nicely release the request
+         * pads when they finalize */
+        gst_bin_remove (bin, priv->udpsrc_v4[i]);
+      } else  {
+        /* we need to set the state to NULL before unref */
+        gst_element_set_state (priv->udpsrc_v4[i], GST_STATE_NULL);
+        gst_object_unref (priv->udpsrc_v4[i]);
+      }
     }
-    if (priv->udpsrc_v6[i] && (priv->sinkpad || i == 1)) {
-      gst_element_set_locked_state (priv->udpsrc_v6[i], FALSE);
-      gst_element_set_state (priv->udpsrc_v6[i], GST_STATE_NULL);
-      gst_bin_remove (bin, priv->udpsrc_v6[i]);
+
+    if (priv->udpsrc_v6[i]) {
+      if (priv->sinkpad || i == 1) {
+        gst_element_set_locked_state (priv->udpsrc_v6[i], FALSE);
+        gst_element_set_state (priv->udpsrc_v6[i], GST_STATE_NULL);
+        gst_bin_remove (bin, priv->udpsrc_v6[i]);
+      } else {
+        gst_element_set_state (priv->udpsrc_v6[i], GST_STATE_NULL);
+        gst_object_unref (priv->udpsrc_v6[i]);
+      }
     }
 
     for (l = priv->transport_sources; l; l = l->next) {