Index: gst/gstpad.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstpad.c,v
retrieving revision 1.515
diff -u -p -r1.515 gstpad.c
--- gst/gstpad.c	12 Jun 2006 09:28:35 -0000	1.515
+++ gst/gstpad.c	17 Jun 2006 19:05:12 -0000
@@ -887,12 +887,14 @@ gst_pad_set_blocked_async (GstPad * pad,
 
   g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
 
-  if (GST_IS_GHOST_PAD (pad)) {
-    pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
-    if (!pad) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    GstPad * tpad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
+    if (was_ghost)
+      gst_object_unref (pad);
+    if (!tpad)
       return FALSE;
-    }
     was_ghost = TRUE;
+    pad = tpad;
   }
 
   GST_OBJECT_LOCK (pad);
Index: gst/gstutils.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstutils.c,v
retrieving revision 1.142
diff -u -p -r1.142 gstutils.c
--- gst/gstutils.c	19 May 2006 10:29:07 -0000	1.142
+++ gst/gstutils.c	17 Jun 2006 19:05:13 -0000
@@ -2788,12 +2788,15 @@ gst_pad_add_data_probe (GstPad * pad, GC
   g_return_val_if_fail (GST_IS_PAD (pad), 0);
   g_return_val_if_fail (handler != NULL, 0);
 
-  if (GST_IS_GHOST_PAD (pad)) {
-    pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
-    if (!pad) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    GstPad * tpad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
+    if (was_ghost)
+      gst_object_unref (pad);
+    if (!tpad) {
       return 0;
     }
     was_ghost = TRUE;
+    pad = tpad;
   }
 
   GST_OBJECT_LOCK (pad);
@@ -2832,12 +2835,15 @@ gst_pad_add_event_probe (GstPad * pad, G
   g_return_val_if_fail (GST_IS_PAD (pad), 0);
   g_return_val_if_fail (handler != NULL, 0);
 
-  if (GST_IS_GHOST_PAD (pad)) {
-    pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
-    if (!pad) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    GstPad * tpad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
+    if (was_ghost)
+      gst_object_unref (pad);
+    if (!tpad) {
       return 0;
     }
     was_ghost = TRUE;
+    pad = tpad;
   }
 
   GST_OBJECT_LOCK (pad);
@@ -2874,12 +2880,15 @@ gst_pad_add_buffer_probe (GstPad * pad, 
   g_return_val_if_fail (GST_IS_PAD (pad), 0);
   g_return_val_if_fail (handler != NULL, 0);
 
-  if (GST_IS_GHOST_PAD (pad)) {
-    pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
-    if (!pad) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    GstPad * tpad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
+    if (was_ghost)
+      gst_object_unref (pad);
+    if (!tpad) {
       return 0;
     }
     was_ghost = TRUE;
+    pad = tpad;
   }
 
   GST_OBJECT_LOCK (pad);
@@ -2911,12 +2920,15 @@ gst_pad_remove_data_probe (GstPad * pad,
   g_return_if_fail (GST_IS_PAD (pad));
   g_return_if_fail (handler_id > 0);
 
-  if (GST_IS_GHOST_PAD (pad)) {
-    pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
-    if (!pad) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    GstPad * tpad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
+    if (was_ghost)
+      gst_object_unref (pad);
+    if (!tpad) {
       return;
     }
     was_ghost = TRUE;
+    pad = tpad;
   }
 
   GST_OBJECT_LOCK (pad);
@@ -2949,12 +2961,15 @@ gst_pad_remove_event_probe (GstPad * pad
   g_return_if_fail (GST_IS_PAD (pad));
   g_return_if_fail (handler_id > 0);
 
-  if (GST_IS_GHOST_PAD (pad)) {
-    pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
-    if (!pad) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    GstPad * tpad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
+    if (was_ghost)
+      gst_object_unref (pad);
+    if (!tpad) {
       return;
     }
     was_ghost = TRUE;
+    pad = tpad;
   }
 
   GST_OBJECT_LOCK (pad);
@@ -2985,11 +3000,14 @@ gst_pad_remove_buffer_probe (GstPad * pa
   g_return_if_fail (handler_id > 0);
 
   if (GST_IS_GHOST_PAD (pad)) {
-    pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
-    if (!pad) {
+    GstPad * tpad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
+    if (was_ghost)
+      gst_object_unref (pad);
+    if (!tpad) {
       return;
     }
     was_ghost = TRUE;
+    pad = tpad;
   }
 
   GST_OBJECT_LOCK (pad);
