? base.diff
? gst_pad_get_parent.diff
? docs/libs/tmpl/gstaudiomixerutils.sgml
? docs/libs/tmpl/gstaudiosink.sgml
? docs/libs/tmpl/gstbaseaudiosink.sgml
? docs/libs/tmpl/gstcddabasesrc.sgml
? docs/libs/tmpl/gsttag.sgml
? docs/libs/tmpl/gsttagid3.sgml
? docs/libs/tmpl/gsttagvorbis.sgml
? docs/libs/tmpl/gstvideofilter.sgml
? docs/libs/tmpl/gstvideosink.sgml
? docs/libs/tmpl/private.sgml
? docs/plugins/tmpl-build.log
? gst-libs/gst/video/libgstvideo_0.10_la-gstvideosink.loT
? tests/examples/volume/volume
Index: ext/libvisual/visual.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/libvisual/visual.c,v
retrieving revision 1.25
diff -u -r1.25 visual.c
--- ext/libvisual/visual.c	27 Feb 2006 12:08:22 -0000	1.25
+++ ext/libvisual/visual.c	6 Mar 2006 21:25:08 -0000
@@ -231,18 +231,20 @@
   GstVisual *visual = GST_VISUAL (gst_pad_get_parent (pad));
   int depths;
 
-  if (!visual->actor)
-    return gst_caps_copy (gst_pad_get_pad_template_caps (visual->srcpad));
+  if (!visual->actor) {
+    ret = gst_caps_copy (gst_pad_get_pad_template_caps (visual->srcpad));
+    goto cleanup;
+  }
 
   ret = gst_caps_new_empty ();
   depths = visual_actor_get_supported_depth (visual->actor);
   if (depths < 0) {
     /* FIXME: set an error */
-    return ret;
+    goto cleanup;
   }
   if (depths == VISUAL_VIDEO_DEPTH_GL) {
     /* We can't handle GL only plugins */
-    return ret;
+    goto cleanup;
   }
 
   GST_DEBUG_OBJECT (visual, "libvisual plugin supports depths %u (0x%04x)",
@@ -261,6 +263,8 @@
     gst_caps_append (ret, gst_caps_from_string (GST_VIDEO_CAPS_RGB_16));
   }
 
+ cleanup:
+  gst_object_unref (visual);
   GST_DEBUG_OBJECT (visual, "returning caps %" GST_PTR_FORMAT, ret);
   return ret;
 }
@@ -277,21 +281,26 @@
   GST_DEBUG_OBJECT (visual, "src pad got caps %" GST_PTR_FORMAT, caps);
 
   if (!gst_structure_get_int (structure, "width", &visual->width))
-    return FALSE;
+    goto error;
   if (!gst_structure_get_int (structure, "height", &visual->height))
-    return FALSE;
+    goto error;
   if (!gst_structure_get_int (structure, "bpp", &depth))
-    return FALSE;
+    goto error;
   if (!gst_structure_get_fraction (structure, "framerate", &visual->fps_n,
           &visual->fps_d))
-    return FALSE;
+    goto error;
 
   visual_video_set_depth (visual->video,
       visual_video_depth_enum_from_value (depth));
   visual_video_set_dimension (visual->video, visual->width, visual->height);
   visual_actor_video_negotiate (visual->actor, 0, FALSE, FALSE);
 
+  gst_object_unref (visual);
   return TRUE;
+
+ error:
+  gst_object_unref (visual);
+  return FALSE;
 }
 
 static gboolean
@@ -303,6 +312,7 @@
   structure = gst_caps_get_structure (caps, 0);
 
   gst_structure_get_int (structure, "rate", &visual->rate);
+  gst_object_unref (visual);
 
   return TRUE;
 }
Index: ext/ogg/gstoggmux.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/ogg/gstoggmux.c,v
retrieving revision 1.66
diff -u -r1.66 gstoggmux.c
--- ext/ogg/gstoggmux.c	5 Mar 2006 23:39:50 -0000	1.66
+++ ext/ogg/gstoggmux.c	6 Mar 2006 21:25:08 -0000
@@ -339,7 +339,7 @@
   name = gst_pad_get_name (pad);
 
   GST_DEBUG_OBJECT (ogg_mux, "sinkconnect triggered on %s", name);
-
+  gst_object_unref (ogg_must);
   g_free (name);
 
   return GST_PAD_LINK_OK;
@@ -461,6 +461,7 @@
   GST_OBJECT_UNLOCK (ogg_mux->collect);
 
   gst_collect_pads_remove_pad (ogg_mux->collect, pad);
+  gst_object_unref (ogg_mux);
 }
 
 /* handle events */
Index: ext/pango/gsttextoverlay.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/pango/gsttextoverlay.c,v
retrieving revision 1.31
diff -u -r1.31 gsttextoverlay.c
--- ext/pango/gsttextoverlay.c	1 Mar 2006 16:24:37 -0000	1.31
+++ ext/pango/gsttextoverlay.c	6 Mar 2006 21:25:08 -0000
@@ -378,10 +378,12 @@
 static void
 gst_text_overlay_init (GstTextOverlay * overlay, GstTextOverlayClass * klass)
 {
+  GstPadTemplate *template;
+
   /* video sink */
-  overlay->video_sinkpad =
-      gst_pad_new_from_template (gst_static_pad_template_get
-      (&video_sink_template_factory), "video_sink");
+  template = gst_static_pad_template_get (&video_sink_template_factory);
+  overlay->video_sinkpad = gst_pad_new_from_template (template, "video_sink");
+  gst_object_unref (template);
   gst_pad_set_getcaps_function (overlay->video_sinkpad,
       GST_DEBUG_FUNCPTR (gst_text_overlay_getcaps));
   gst_pad_set_setcaps_function (overlay->video_sinkpad,
@@ -394,9 +396,9 @@
 
   if (!GST_IS_TIME_OVERLAY_CLASS (klass) && !GST_IS_CLOCK_OVERLAY_CLASS (klass)) {
     /* text sink */
-    overlay->text_sinkpad =
-        gst_pad_new_from_template (gst_static_pad_template_get
-        (&text_sink_template_factory), "text_sink");
+    template = gst_static_pad_template_get (&text_sink_template_factory);
+    overlay->text_sinkpad = gst_pad_new_from_template (template, "text_sink");
+    gst_object_unref (template);
     gst_pad_set_event_function (overlay->text_sinkpad,
         GST_DEBUG_FUNCPTR (gst_text_overlay_text_event));
     gst_pad_set_chain_function (overlay->text_sinkpad,
@@ -409,9 +411,9 @@
   }
 
   /* (video) source */
-  overlay->srcpad =
-      gst_pad_new_from_template (gst_static_pad_template_get
-      (&src_template_factory), "src");
+  template = gst_static_pad_template_get (&src_template_factory);
+  overlay->srcpad = gst_pad_new_from_template (template, "src");
+  gst_object_unref (template);
   gst_pad_set_getcaps_function (overlay->srcpad,
       GST_DEBUG_FUNCPTR (gst_text_overlay_getcaps));
   gst_pad_set_event_function (overlay->srcpad,
Index: ext/pango/gsttextrender.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/pango/gsttextrender.c,v
retrieving revision 1.4
diff -u -r1.4 gsttextrender.c
--- ext/pango/gsttextrender.c	5 Dec 2005 13:02:12 -0000	1.4
+++ ext/pango/gsttextrender.c	6 Mar 2006 21:25:08 -0000
@@ -326,18 +326,20 @@
 static void
 gst_text_render_init (GstTextRender * render, GstTextRenderClass * klass)
 {
+  GstPadTemplate *template;
+
   /* sink */
-  render->sinkpad =
-      gst_pad_new_from_template (gst_static_pad_template_get
-      (&sink_template_factory), "sink");
+  template = gst_static_pad_template_get (&sink_template_factory);
+  render->sinkpad = gst_pad_new_from_template (template, "sink");
+  gst_object_unref (template);
   gst_pad_set_chain_function (render->sinkpad,
       GST_DEBUG_FUNCPTR (gst_text_render_chain));
   gst_element_add_pad (GST_ELEMENT (render), render->sinkpad);
 
   /* source */
-  render->srcpad =
-      gst_pad_new_from_template (gst_static_pad_template_get
-      (&src_template_factory), "src");
+  template = gst_static_pad_template_get (&src_template_factory);
+  render->srcpad = gst_pad_new_from_template (template, "src");
+  gst_object_unref (template);
   gst_pad_set_fixatecaps_function (render->srcpad,
       GST_DEBUG_FUNCPTR (gst_text_render_fixate_caps));
   gst_pad_set_setcaps_function (render->srcpad,
Index: ext/vorbis/vorbisenc.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/vorbis/vorbisenc.c,v
retrieving revision 1.106
diff -u -r1.106 vorbisenc.c
--- ext/vorbis/vorbisenc.c	5 Mar 2006 22:57:58 -0000	1.106
+++ ext/vorbis/vorbisenc.c	6 Mar 2006 21:25:08 -0000
@@ -309,8 +309,10 @@
   vorbisenc = GST_VORBISENC (gst_pad_get_parent (pad));
 
   if (vorbisenc->samples_in == 0 ||
-      vorbisenc->bytes_out == 0 || vorbisenc->frequency == 0)
+      vorbisenc->bytes_out == 0 || vorbisenc->frequency == 0) {
+    gst_object_unref (vorbisenc);
     return FALSE;
+  }
 
   avg = (vorbisenc->bytes_out * vorbisenc->frequency) / (vorbisenc->samples_in);
 
@@ -336,6 +338,7 @@
     default:
       res = FALSE;
   }
+  gst_object_unref (vorbisenc);
   return res;
 }
 
@@ -407,6 +410,7 @@
     default:
       res = FALSE;
   }
+  gst_object_unref (vorbisenc);
   return res;
 }
 
Index: gst/adder/gstadder.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst/adder/gstadder.c,v
retrieving revision 1.73
diff -u -r1.73 gstadder.c
--- gst/adder/gstadder.c	1 Feb 2006 11:56:11 -0000	1.73
+++ gst/adder/gstadder.c	6 Mar 2006 21:25:08 -0000
@@ -272,9 +272,11 @@
 static void
 gst_adder_init (GstAdder * adder)
 {
-  adder->srcpad =
-      gst_pad_new_from_template (gst_static_pad_template_get
-      (&gst_adder_src_template), "src");
+  GstPadTemplate *template;
+  
+  template = gst_static_pad_template_get (&gst_adder_src_template);
+  adder->srcpad = gst_pad_new_from_template (template, "src");
+  gst_object_unref (template);
   gst_pad_set_getcaps_function (adder->srcpad,
       GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
   gst_pad_set_setcaps_function (adder->srcpad,
Index: gst/audiorate/gstaudiorate.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst/audiorate/gstaudiorate.c,v
retrieving revision 1.15
diff -u -r1.15 gstaudiorate.c
--- gst/audiorate/gstaudiorate.c	10 Jan 2006 15:47:48 -0000	1.15
+++ gst/audiorate/gstaudiorate.c	6 Mar 2006 21:25:08 -0000
@@ -204,21 +204,25 @@
   otherpad = (pad == audiorate->srcpad) ? audiorate->sinkpad :
       audiorate->srcpad;
 
-  if (!gst_pad_set_caps (otherpad, caps))
+  if (!gst_pad_set_caps (otherpad, caps)) {
+    gst_object_unref (audiorate);
     return FALSE;
+  }
 
   structure = gst_caps_get_structure (caps, 0);
 
   ret = gst_structure_get_int (structure, "channels", &channels);
   ret &= gst_structure_get_int (structure, "width", &width);
 
-  if (!ret)
+  if (!ret) {
+    gst_object_unref (audiorate);
     return FALSE;
+  }
 
   audiorate->bytes_per_sample = channels * (width / 8);
   if (audiorate->bytes_per_sample == 0)
     audiorate->bytes_per_sample = 1;
-
+  gst_object_unref (audiorate);
   return TRUE;
 }
 
@@ -352,6 +356,7 @@
   audiorate->next_offset = in_offset_end;
 beach:
   audiorate->offset += in_size / audiorate->bytes_per_sample;
+  gst_object_unref (audiorate);
   return ret;
 }
 
Index: gst-libs/gst/audio/audio.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst-libs/gst/audio/audio.c,v
retrieving revision 1.26
diff -u -r1.26 audio.c
--- gst-libs/gst/audio/audio.c	22 Nov 2005 13:14:07 -0000	1.26
+++ gst-libs/gst/audio/audio.c	6 Mar 2006 21:25:08 -0000
@@ -45,9 +45,12 @@
   caps = GST_PAD_CAPS (pad);
 
   if (caps == NULL) {
+    GstElement *elem;
     /* ERROR: could not get caps of pad */
+    elem = GST_ELEMENT (gst_pad_get_parent (pad));
     g_warning ("gstaudio: could not get caps of pad %s:%s\n",
-        GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
+        GST_ELEMENT_NAME (elem), GST_PAD_NAME (pad));
+    gst_object_unref (elem);
     return 0;
   }
 
@@ -100,10 +103,13 @@
   /* get caps of pad */
   caps = GST_PAD_CAPS (pad);
   if (caps == NULL) {
+    GstElement *elem;
     /* ERROR: could not get caps of pad */
+    elem = GST_ELEMENT (gst_pad_get_parent (pad));
     g_warning ("gstaudio: could not get caps of pad %s:%s\n",
-        GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
+        GST_ELEMENT_NAME (elem), GST_PAD_NAME (pad));
     length = GST_CLOCK_TIME_NONE;
+    gst_object_unref (elem);
   } else {
     structure = gst_caps_get_structure (caps, 0);
     bytes = GST_BUFFER_SIZE (buf);
Index: gst-libs/gst/audio/gstaudiofilter.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst-libs/gst/audio/gstaudiofilter.c,v
retrieving revision 1.17
diff -u -r1.17 gstaudiofilter.c
--- gst-libs/gst/audio/gstaudiofilter.c	1 Dec 2005 14:29:09 -0000	1.17
+++ gst-libs/gst/audio/gstaudiofilter.c	6 Mar 2006 21:25:08 -0000
@@ -136,6 +136,7 @@
   }
 
   if (GST_PAD_LINK_FAILED (link_ret)) {
+    gst_object_unref (audiofilter);
     return link_ret;
   }
 
@@ -153,8 +154,10 @@
   ret &= gst_structure_get_int (structure, "rate", &audiofilter->rate);
   ret &= gst_structure_get_int (structure, "channels", &audiofilter->channels);
 
-  if (!ret)
+  if (!ret) {
+    gst_object_unref (audiofilter);
     return GST_PAD_LINK_REFUSED;
+  }
 
   audiofilter->bytes_per_sample = (audiofilter->width / 8) *
       audiofilter->channels;
@@ -162,7 +165,7 @@
   if (audio_filter_class->setup)
     (audio_filter_class->setup) (audiofilter);
 #endif
-
+  gst_object_unref (audiofilter);
   return GST_PAD_LINK_OK;
 }
 
@@ -217,6 +220,7 @@
       GST_BUFFER_SIZE (inbuf), GST_OBJECT_NAME (audiofilter));
 
   if (audiofilter->passthru) {
+    gst_object_unref (audiofilter);
     gst_pad_push (audiofilter->srcpad, buffer);
     return GST_FLOW_OK;
   }
@@ -252,7 +256,7 @@
   }
 
   gst_pad_push (audiofilter->srcpad, outbuf);
-
+  gst_object_unref (audiofilter);
   return GST_FLOW_OK;
 }
 
Index: gst-libs/gst/rtp/gstbasertpdepayload.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst-libs/gst/rtp/gstbasertpdepayload.c,v
retrieving revision 1.29
diff -u -r1.29 gstbasertpdepayload.c
--- gst-libs/gst/rtp/gstbasertpdepayload.c	2 Feb 2006 00:04:37 -0000	1.29
+++ gst-libs/gst/rtp/gstbasertpdepayload.c	6 Mar 2006 21:25:08 -0000
@@ -175,6 +175,7 @@
 {
   GstBaseRTPDepayload *filter;
   GstBaseRTPDepayloadClass *bclass;
+  gboolean result;
 
   filter = GST_BASE_RTP_DEPAYLOAD (gst_pad_get_parent (pad));
   g_return_val_if_fail (filter != NULL, FALSE);
@@ -183,9 +184,12 @@
   bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
 
   if (bclass->set_caps)
-    return bclass->set_caps (filter, caps);
+    result = bclass->set_caps (filter, caps);
   else
-    return TRUE;
+    result = TRUE;
+
+  gst_object_unref (filter);
+  return result;
 }
 
 static GstFlowReturn
Index: gst-libs/gst/video/video.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst-libs/gst/video/video.c,v
retrieving revision 1.15
diff -u -r1.15 video.c
--- gst-libs/gst/video/video.c	22 Nov 2005 16:08:36 -0000	1.15
+++ gst-libs/gst/video/video.c	6 Mar 2006 21:25:08 -0000
@@ -33,32 +33,39 @@
 
   const GstCaps *caps = NULL;
   GstStructure *structure;
+  GstElement *elem;
 
   /* get pad caps */
   caps = GST_PAD_CAPS (pad);
+  elem = GST_ELEMENT (gst_pad_get_parent (pad));
+
   if (caps == NULL) {
     g_warning ("gstvideo: failed to get caps of pad %s:%s",
-        GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
+        GST_ELEMENT_NAME (elem), GST_PAD_NAME (pad));
+    gst_object_unref (elem);
     return NULL;
   }
 
   structure = gst_caps_get_structure (caps, 0);
   if ((fps = gst_structure_get_value (structure, "framerate")) == NULL) {
     g_warning ("gstvideo: failed to get framerate property of pad %s:%s",
-        GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
+        GST_ELEMENT_NAME (elem), GST_PAD_NAME (pad));
+    gst_object_unref (elem);
     return NULL;
   }
   if (!GST_VALUE_HOLDS_FRACTION (fps)) {
     g_warning
         ("gstvideo: framerate property of pad %s:%s is not of type Fraction",
-        GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
+        GST_ELEMENT_NAME (elem), GST_PAD_NAME (pad));
+    gst_object_unref (elem);
     return NULL;
   }
 
   fps_string = gst_value_serialize (fps);
   GST_DEBUG ("Framerate request on pad %s:%s: %s",
-      GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad),
+      GST_ELEMENT_NAME (elem), GST_PAD_NAME (pad),
       fps_string);
+  gst_object_unref (elem);
   g_free (fps_string);
 
   return fps;
@@ -70,16 +77,18 @@
   const GstCaps *caps = NULL;
   GstStructure *structure;
   gboolean ret;
+  GstElement *elem;
 
   g_return_val_if_fail (pad != NULL, FALSE);
   g_return_val_if_fail (width != NULL, FALSE);
   g_return_val_if_fail (height != NULL, FALSE);
 
   caps = GST_PAD_CAPS (pad);
-
+  elem = GST_ELEMENT (gst_pad_get_parent (pad));
   if (caps == NULL) {
     g_warning ("gstvideo: failed to get caps of pad %s:%s",
-        GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
+        GST_ELEMENT_NAME (elem), GST_PAD_NAME (pad));
+    gst_object_unref (elem);
     return FALSE;
   }
 
@@ -89,13 +98,15 @@
 
   if (!ret) {
     g_warning ("gstvideo: failed to get size properties on pad %s:%s",
-        GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad));
+        GST_ELEMENT_NAME (elem), GST_PAD_NAME (pad));
+    gst_object_unref (elem);
     return FALSE;
   }
 
   GST_DEBUG ("size request on pad %s:%s: %dx%d",
-      GST_ELEMENT_NAME (gst_pad_get_parent (pad)),
+      GST_ELEMENT_NAME (elem),
       GST_PAD_NAME (pad), width ? *width : -1, height ? *height : -1);
+  gst_object_unref (elem);
 
   return TRUE;
 }
Index: sys/v4l/gstv4ljpegsrc.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/sys/v4l/gstv4ljpegsrc.c,v
retrieving revision 1.2
diff -u -r1.2 gstv4ljpegsrc.c
--- sys/v4l/gstv4ljpegsrc.c	22 Nov 2005 23:39:12 -0000	1.2
+++ sys/v4l/gstv4ljpegsrc.c	6 Mar 2006 21:25:08 -0000
@@ -121,6 +121,7 @@
   GstStructure *structure;
   gboolean was_capturing;
   struct video_window *vwin;
+  GstPadLinkReturn result;
 
   v4ljpegsrc = GST_V4LJPEGSRC (gst_pad_get_parent (pad));
   v4lsrc = GST_V4LSRC (v4ljpegsrc);
@@ -131,13 +132,18 @@
    * did capsnego before and didn't clean up), clean up anyways */
   if (GST_V4L_IS_ACTIVE (GST_V4LELEMENT (v4lsrc))) {
     if (was_capturing) {
-      if (!gst_v4lsrc_capture_stop (v4lsrc))
-        return GST_PAD_LINK_REFUSED;
+      if (!gst_v4lsrc_capture_stop (v4lsrc)) {
+        result = GST_PAD_LINK_REFUSED;
+	goto cleanup;
+      }
+    }
+    if (!gst_v4lsrc_capture_deinit (v4lsrc)) {
+      result = GST_PAD_LINK_REFUSED;
+      goto cleanup;
     }
-    if (!gst_v4lsrc_capture_deinit (v4lsrc))
-      return GST_PAD_LINK_REFUSED;
   } else if (!GST_V4L_IS_OPEN (GST_V4LELEMENT (v4lsrc))) {
-    return GST_PAD_LINK_DELAYED;
+    result GST_PAD_LINK_DELAYED;
+    goto cleanup;
   }
 
   structure = gst_caps_get_structure (vscapslist, 0);
@@ -160,7 +166,8 @@
     /* set bits 16 to 21 to the index */
     vwin->flags |= fps_index << 16;
     if (!gst_v4l_set_window_properties (GST_V4LELEMENT (v4lsrc))) {
-      return GST_PAD_LINK_DELAYED;
+      result = GST_PAD_LINK_DELAYED;
+      goto cleanup;
     }
   }
 
@@ -176,70 +183,83 @@
   if (!gst_v4lsrc_set_capture (v4lsrc, w, h, palette)) {
     GST_WARNING_OBJECT (v4ljpegsrc, "could not set_capture %dx%d, palette %d",
         w, h, palette);
-    return GST_PAD_LINK_REFUSED;
+    result = GST_PAD_LINK_REFUSED;
+    goto cleanup;
   }
 
   /* first try the negotiated settings using try_capture */
   if (!gst_v4lsrc_try_capture (v4lsrc, w, h, palette)) {
     GST_DEBUG_OBJECT (v4ljpegsrc, "failed trying palette %d for %dx%d", palette,
         w, h);
-    return GST_PAD_LINK_REFUSED;
+    result = GST_PAD_LINK_REFUSED;
+    goto cleanup;
   }
 
-  if (!gst_v4lsrc_capture_init (v4lsrc))
-    return GST_PAD_LINK_REFUSED;
+  if (!gst_v4lsrc_capture_init (v4lsrc)) {
+    result = GST_PAD_LINK_REFUSED;
+    goto cleanup;
+  }
 
   if (was_capturing || GST_STATE (v4lsrc) == GST_STATE_PLAYING) {
-    if (!gst_v4lsrc_capture_start (v4lsrc))
-      return GST_PAD_LINK_REFUSED;
+    if (!gst_v4lsrc_capture_start (v4lsrc)) {
+      result = GST_PAD_LINK_REFUSED;
+      goto cleanup;
+    }
   }
 
-  return GST_PAD_LINK_OK;
+  result = GST_PAD_LINK_OK;
+ cleanup:
+  gst_element_unref (v4ljpegsrc);
+  return result;
 }
 
 static GstCaps *
 gst_v4ljpegsrc_getcaps (GstPad * pad)
 {
-  GstCaps *list;
-  GstV4lJpegSrc *v4ljpegsrc = GST_V4LJPEGSRC (gst_pad_get_parent (pad));
+  GstCaps *result;
+  GstElement *elem = GST_ELEMENT (gst_pad_get_parent (pad));
+  GstV4lJpegSrc *v4ljpegsrc = GST_V4LJPEGSRC (elem);
   GstV4lSrc *v4lsrc = GST_V4LSRC (v4ljpegsrc);
   struct video_capability *vcap = &GST_V4LELEMENT (v4lsrc)->vcap;
   gfloat fps = 0.0;
 
   if (!GST_V4L_IS_OPEN (GST_V4LELEMENT (v4lsrc))) {
-    return gst_caps_new_any ();
+    result = gst_caps_new_any ();
+    goto cleanup;
   }
   if (!v4lsrc->autoprobe) {
     /* FIXME: query current caps and return those, with _any appended */
-    return gst_caps_new_any ();
+    result = gst_caps_new_any ();
+    goto cleanup;
   }
 
-  list = gst_caps_new_simple ("image/jpeg", NULL);
+  result = gst_caps_new_simple ("image/jpeg", NULL);
   GST_DEBUG_OBJECT (v4ljpegsrc,
       "Device reports w: %d-%d, h: %d-%d, fps: %f",
       vcap->minwidth, vcap->maxwidth, vcap->minheight, vcap->maxheight, fps);
 
   if (vcap->minwidth < vcap->maxwidth) {
-    gst_caps_set_simple (list, "width", GST_TYPE_INT_RANGE, vcap->minwidth,
+    gst_caps_set_simple (result, "width", GST_TYPE_INT_RANGE, vcap->minwidth,
         vcap->maxwidth, NULL);
   } else {
-    gst_caps_set_simple (list, "width", G_TYPE_INT, vcap->minwidth, NULL);
+    gst_caps_set_simple (result, "width", G_TYPE_INT, vcap->minwidth, NULL);
   }
   if (vcap->minheight < vcap->maxheight) {
-    gst_caps_set_simple (list, "height", GST_TYPE_INT_RANGE, vcap->minheight,
+    gst_caps_set_simple (result, "height", GST_TYPE_INT_RANGE, vcap->minheight,
         vcap->maxheight, NULL);
   } else {
-    gst_caps_set_simple (list, "height", G_TYPE_INT, vcap->minheight, NULL);
+    gst_caps_set_simple (result, "height", G_TYPE_INT, vcap->minheight, NULL);
   }
 
   if (v4lsrc->fps_list) {
-    GstStructure *structure = gst_caps_get_structure (list, 0);
+    GstStructure *structure = gst_caps_get_structure (result, 0);
 
     gst_structure_set_value (structure, "framerate", v4lsrc->fps_list);
   }
-  GST_DEBUG_OBJECT (v4ljpegsrc, "caps: %" GST_PTR_FORMAT, list);
-
-  return list;
+  GST_DEBUG_OBJECT (v4ljpegsrc, "caps: %" GST_PTR_FORMAT, result);
+ cleanup:
+  gst_object_unref (elem);
+  return result;
 }
 
 static GstData *
