qt-gstreamer: qtvideosink: let BufferEvent keep its own reference on the GstBuffer

George Kiagiadakis gkiagia at kemper.freedesktop.org
Tue Feb 7 09:13:28 PST 2012


Module: qt-gstreamer
Branch: master
Commit: 08beaf91bf2b046eed07af44d70a72fdecf87a04
URL:    http://cgit.freedesktop.org/gstreamer/qt-gstreamer/commit/?id=08beaf91bf2b046eed07af44d70a72fdecf87a04

Author: George Kiagiadakis <george.kiagiadakis at collabora.com>
Date:   Tue Feb  7 00:25:35 2012 +0200

qtvideosink: let BufferEvent keep its own reference on the GstBuffer

Although the previous approach also looks correct, in fact there is one
case where handing over the reference can cause a memory leak. This is
the case where a buffer event is posted on the event loop, but the
sink is destroyed before this event is delivered. In this case, the
event will be discarded by the event dispatcher, but the GstBuffer
will never be unreferenced. This patch ensures that this will never
happen.

---

 elements/gstqtvideosink/qtvideosinkdelegate.cpp |    5 +----
 elements/gstqtvideosink/qtvideosinkdelegate.h   |    5 ++++-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/elements/gstqtvideosink/qtvideosinkdelegate.cpp b/elements/gstqtvideosink/qtvideosinkdelegate.cpp
index 9515493..ad9cd62 100644
--- a/elements/gstqtvideosink/qtvideosinkdelegate.cpp
+++ b/elements/gstqtvideosink/qtvideosinkdelegate.cpp
@@ -369,14 +369,11 @@ bool QtVideoSinkDelegate::event(QEvent *event)
 
         if (isActive()) {
             //schedule this frame for rendering
-            m_buffer = bufEvent->buffer;
+            m_buffer = gst_buffer_ref(bufEvent->buffer);
             if (bufEvent->formatDirty) {
                 m_formatDirty = true;
             }
             update();
-        } else {
-            //not active, drop the frame
-            gst_buffer_unref(bufEvent->buffer);
         }
 
         return true;
diff --git a/elements/gstqtvideosink/qtvideosinkdelegate.h b/elements/gstqtvideosink/qtvideosinkdelegate.h
index 7ddec6e..a97e82b 100644
--- a/elements/gstqtvideosink/qtvideosinkdelegate.h
+++ b/elements/gstqtvideosink/qtvideosinkdelegate.h
@@ -55,7 +55,10 @@ public:
             : QEvent(static_cast<QEvent::Type>(BufferEventType)),
               buffer(gst_buffer_ref(buf)),
               formatDirty(formatDirty)
-        {
+        {}
+
+        virtual ~BufferEvent() {
+            gst_buffer_unref(buffer);
         }
 
         GstBuffer *buffer;



More information about the gstreamer-commits mailing list