Index: gst/gstpad.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstpad.c,v
retrieving revision 1.511
diff -u -p -r1.511 gstpad.c
--- gst/gstpad.c	4 May 2006 16:34:20 -0000	1.511
+++ gst/gstpad.c	5 May 2006 17:31:15 -0000
@@ -883,7 +883,10 @@ gst_pad_set_blocked_async (GstPad * pad,
 
   g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
 
-  if (GST_IS_GHOST_PAD (pad)) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    if (was_ghost)
+      gst_object_unref (pad);
+
     pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
     if (!pad) {
       return FALSE;
Index: gst/gstutils.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstutils.c,v
retrieving revision 1.140
diff -u -p -r1.140 gstutils.c
--- gst/gstutils.c	4 May 2006 15:20:14 -0000	1.140
+++ gst/gstutils.c	5 May 2006 17:31:16 -0000
@@ -2754,7 +2754,9 @@ 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)) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    if (was_ghost)
+      gst_object_unref (pad);
     pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
     if (!pad) {
       return 0;
@@ -2798,7 +2800,9 @@ 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)) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    if (was_ghost)
+      gst_object_unref (pad);
     pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
     if (!pad) {
       return 0;
@@ -2840,7 +2844,9 @@ 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)) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    if (was_ghost)
+      gst_object_unref (pad);
     pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
     if (!pad) {
       return 0;
@@ -2877,7 +2883,9 @@ 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)) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    if (was_ghost)
+      gst_object_unref (pad);
     pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
     if (!pad) {
       return;
@@ -2915,7 +2923,9 @@ 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)) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    if (was_ghost)
+      gst_object_unref (pad);
     pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
     if (!pad) {
       return;
@@ -2950,7 +2960,9 @@ gst_pad_remove_buffer_probe (GstPad * pa
   g_return_if_fail (GST_IS_PAD (pad));
   g_return_if_fail (handler_id > 0);
 
-  if (GST_IS_GHOST_PAD (pad)) {
+  while (GST_IS_GHOST_PAD (pad)) {
+    if (was_ghost)
+      gst_object_unref (pad);
     pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
     if (!pad) {
       return;
Index: tests/check/gst/gstghostpad.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/tests/check/gst/gstghostpad.c,v
retrieving revision 1.19
diff -u -p -r1.19 gstghostpad.c
--- tests/check/gst/gstghostpad.c	29 Apr 2006 00:33:44 -0000	1.19
+++ tests/check/gst/gstghostpad.c	5 May 2006 17:31:16 -0000
@@ -386,6 +386,98 @@ GST_START_TEST (test_ghost_pads_bin)
 
 GST_END_TEST;
 
+/*
+ * Test if probes on ghostpads of ghostpads get set and triggered
+ */
+
+static gboolean
+multi_ghostpad_data_probe (GstPad * pad, GstMiniObject * object, guint * pdata)
+{
+  GST_DEBUG_OBJECT (pad, "pdata:%d", *pdata);
+  *pdata +=1 ;
+  return FALSE;
+}
+
+static gboolean
+multi_ghostpad_buffer_probe (GstPad * pad, GstMiniObject * object, guint * pbuffer)
+{
+  GST_DEBUG_OBJECT (pad, "pbuffer:%d", *pbuffer);
+  *pbuffer += 1;
+  return FALSE;
+}
+
+static gboolean
+multi_ghostpad_event_probe (GstPad * pad, GstMiniObject * object, guint * pevent)
+{
+  GST_DEBUG_OBJECT (pad, "pevent:%d", *pevent);
+  *pevent += 1;
+  return FALSE;
+}
+
+GST_START_TEST (test_multi_ghost_pads_probe)
+{
+  GstBin *pipeline;
+  GstBin *bin1, *bin2, *bin3;
+  GstPad *pad, *ghostpad1, *ghostpad2;
+  GstBuffer *buffer;
+  GstEvent *event;
+  guint events = 0;
+  guint buffers = 0;
+  guint data = 0;
+  gulong probeid = 0;
+
+  pipeline = GST_BIN (gst_pipeline_new("pipe"));
+
+  bin1 = GST_BIN (gst_bin_new ("bin1"));
+  bin2 = GST_BIN (gst_bin_new ("bin2"));
+  bin3 = GST_BIN (gst_bin_new ("bin3"));
+
+  pad = gst_pad_new ("srcpad", GST_PAD_SRC);
+  gst_element_add_pad (GST_ELEMENT (bin1), pad);
+
+  gst_bin_add (bin2, GST_ELEMENT (bin1));
+  gst_bin_add (bin3, GST_ELEMENT (bin2));
+  gst_bin_add (pipeline, GST_ELEMENT (bin3));
+
+  ghostpad1 = gst_ghost_pad_new ("ghost1", pad);
+  gst_element_add_pad (GST_ELEMENT (bin2), ghostpad1);
+
+  ghostpad2 = gst_ghost_pad_new ("ghost2", ghostpad1);
+  gst_element_add_pad (GST_ELEMENT (bin3), ghostpad2);
+
+  probeid = gst_pad_add_data_probe (ghostpad2, G_CALLBACK (multi_ghostpad_data_probe), &data);
+
+  buffer = gst_buffer_new ();
+  event = gst_event_new_eos ();
+
+  gst_pad_push (pad, buffer);
+  gst_pad_push_event (pad, event);
+
+  fail_if (events != 0);
+  fail_if (buffers != 0);
+  fail_if (data != 2);
+
+  gst_pad_remove_data_probe (ghostpad2, probeid);
+
+  data = 0;
+
+  gst_pad_add_buffer_probe (ghostpad2, G_CALLBACK (multi_ghostpad_buffer_probe), &buffers);
+  gst_pad_add_event_probe (ghostpad2, G_CALLBACK (multi_ghostpad_event_probe), &events);
+
+  buffer = gst_buffer_new ();
+  event = gst_event_new_eos ();
+
+  gst_pad_push (pad, buffer);
+  gst_pad_push_event (pad, event);
+
+  fail_if (events != 1);
+  fail_if (buffers != 1);
+  fail_if (data != 0);
+
+}
+
+GST_END_TEST;
+
 Suite *
 gst_ghost_pad_suite (void)
 {
@@ -398,6 +490,7 @@ gst_ghost_pad_suite (void)
   tcase_add_test (tc_chain, test_link);
   tcase_add_test (tc_chain, test_ghost_pads);
   tcase_add_test (tc_chain, test_ghost_pads_bin);
+  tcase_add_test (tc_chain, test_multi_ghost_pads_probe);
 /*  tcase_add_test (tc_chain, test_ghost_pad_notarget); */
 
   return s;
