--- gstdecodebin2.c.orig	2007-04-02 14:36:47.000000000 +0300
+++ gstdecodebin2.c	2007-04-02 14:32:26.000000000 +0300
@@ -834,6 +837,7 @@
     GList * factories, GstDecodeGroup * group)
 {
   gboolean res = FALSE;
+  GstPad *mqpad = NULL;
   GList *tmp;
 
   g_return_val_if_fail (factories != NULL, FALSE);
@@ -842,7 +846,6 @@
 
   /* 1. is element demuxer or parser */
   if (is_demuxer_element (src)) {
-    GstPad *mqpad;
 
     GST_LOG_OBJECT (src, "is a demuxer, connecting the pad through multiqueue");
 
@@ -909,6 +912,7 @@
       continue;
     }
 
+    gst_object_unref (sinkpad);
     GST_LOG_OBJECT (dbin, "linked on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
 
     /* link this element further */
@@ -920,7 +924,6 @@
       GST_WARNING_OBJECT (dbin, "Couldn't set %s to PAUSED",
           GST_ELEMENT_NAME (element));
       gst_element_set_state (element, GST_STATE_NULL);
-      gst_object_unref (sinkpad);
       gst_bin_remove (GST_BIN (dbin), element);
       continue;
     }
@@ -929,6 +932,9 @@
     break;
   }
 
+  if (mqpad) {
+    gst_object_unref (mqpad);
+  }
 beach:
   return res;
 }
@@ -1058,6 +1064,7 @@
 {
   gboolean newgroup = FALSE;
   gboolean isdemux;
+  GstPad *mqpad = NULL;
 
   GST_DEBUG_OBJECT (dbin, "pad %s:%s, group:%p",
       GST_DEBUG_PAD_NAME (pad), group);
@@ -1074,7 +1081,6 @@
   isdemux = is_demuxer_element (src);
 
   if (isdemux || newgroup) {
-    GstPad *mqpad;
 
     GST_LOG_OBJECT (src, "is a demuxer, connecting the pad through multiqueue");
 
@@ -1091,6 +1097,10 @@
      * group as being complete. */
     gst_decode_group_set_complete (group);
   }
+
+  if (mqpad) {
+    gst_object_unref (mqpad);
+  }
 beach:
   return;
 }
@@ -1824,6 +1834,7 @@
 
         if ((peerpad = gst_pad_get_peer (pad))) {
           GstObject *parent = gst_pad_get_parent (peerpad);
+          gst_object_unref (peerpad);
 
           if (parent && GST_IS_ELEMENT (parent))
             deactivate_free_recursive (group, GST_ELEMENT (parent));
