[gstreamermm] Gst::Pad: fix ref leak (bgo#751504)



commit 2c662caac0ed965886dd82d57d0e3d9e25a125a5
Author: Marcin Kolny <marcin kolny flytronic pl>
Date:   Mon Jun 29 14:59:48 2015 +0200

    Gst::Pad: fix ref leak (bgo#751504)
    
        * gstreamer/src/pad.{ccg|hg}: fix ref leak in
          get_pad_template_caps method, add non-const version of this method.
        * tests/test-pad.cc: add tests for get_pad_template_caps method.

 gstreamer/src/pad.ccg |   10 ----------
 gstreamer/src/pad.hg  |    9 ++-------
 tests/test-pad.cc     |   10 ++++++++++
 3 files changed, 12 insertions(+), 17 deletions(-)
---
diff --git a/gstreamer/src/pad.ccg b/gstreamer/src/pad.ccg
index 042a621..1f4b458 100644
--- a/gstreamer/src/pad.ccg
+++ b/gstreamer/src/pad.ccg
@@ -137,16 +137,6 @@ gulong Pad::add_probe(PadProbeType mask, const SlotProbe& slot)
     return gst_pad_add_probe(gobj(), static_cast<GstPadProbeType>(mask), &Pad_Probe_gstreamermm_callback, 
slot_copy, &Pad_Probe_gstreamermm_callback_disconnect);
 }
 
-// This is handcoded because the documentation tells us that we need to copy
-// the Caps
-Glib::RefPtr<const Gst::Caps> Pad::get_pad_template_caps() const
-{
-  const GstCaps* caps = gst_pad_get_pad_template_caps(const_cast<GstPad*>(gobj()));
-  GstCaps* copy_caps = gst_caps_copy(caps);
-  return Glib::wrap(copy_caps, false);
-}
-
-
 FlowReturn Pad::get_range(guint64 offset, guint size, Glib::RefPtr<Gst::Buffer>& buffer)
 {
   GstBuffer* c_buffer = 0;
diff --git a/gstreamer/src/pad.hg b/gstreamer/src/pad.hg
index 23aad4d..45653ec 100644
--- a/gstreamer/src/pad.hg
+++ b/gstreamer/src/pad.hg
@@ -178,13 +178,8 @@ public:
   _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_allowed_caps(), gst_pad_get_allowed_caps)
   _WRAP_METHOD(Glib::RefPtr<const Gst::Caps> get_allowed_caps() const, gst_pad_get_allowed_caps, 
constversion)
 
-  //The documentation gst_pad_get_pad_template_caps() suggests that there shouldn't be a non-const return:
-  /** Gets the capabilities for pad's template.
-   *
-   * @return The Gst::Caps of this pad template.
-   */
-  Glib::RefPtr<const Gst::Caps> get_pad_template_caps() const;
-  _IGNORE(gst_pad_get_pad_template_caps)
+  _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_pad_template_caps(), gst_pad_get_pad_template_caps)
+  _WRAP_METHOD(Glib::RefPtr<const Gst::Caps> get_pad_template_caps() const, gst_pad_get_pad_template_caps, 
constversion)
 
   gulong add_probe(PadProbeType mask, const SlotProbe& slot);
   _WRAP_METHOD(void remove_probe(gulong id), gst_pad_remove_probe)
diff --git a/tests/test-pad.cc b/tests/test-pad.cc
index 18ff7c0..e8b8ce7 100644
--- a/tests/test-pad.cc
+++ b/tests/test-pad.cc
@@ -49,3 +49,13 @@ TEST_F(PadTest, PadCorrectCreatedUsingTemplate)
     CheckPad();
 }
 
+TEST_F(PadTest, PadVerifyGetPadTemplateCaps)
+{
+    Glib::RefPtr<Gst::Caps> caps;
+    {
+        Glib::RefPtr<PadTemplate> pad_tpl =
+            PadTemplate::create("source-template", pad_direction, PAD_ALWAYS, Caps::create_any());
+        caps = Pad::create(pad_tpl, pad_name)->get_pad_template_caps();
+    }
+    ASSERT_EQ(1, caps->get_refcount());
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]