From 0d11ed2f1bb39a0ffdf55beeabbbdc5bdd5ac357 Mon Sep 17 00:00:00 2001 From: Piotr Srebrny Date: Thu, 16 Dec 2021 18:33:46 +0100 Subject: Don't leak GStramer bus object, make virtual destructor in base class This patch removes an unnecessary reference increment on the bus object in QGstPipelinePrivate as the bus is owned by QGstPipelinePrivate. Add virtual destructor in the QGstObject as QGstPipeline inherits from it. Provide correct handling of self-assignment operation for QGstPipeline and QGstObject. Change-Id: I41a333be8c2d8596aa1d11a9e1c11f4410ed6283 Reviewed-by: Lars Knoll (cherry picked from commit 77096edebd7dda161db42b92a5b3bc41f9c69740) Reviewed-by: Qt Cherry-pick Bot --- src/multimedia/platform/gstreamer/common/qgst_p.h | 4 +++- src/multimedia/platform/gstreamer/common/qgstpipeline.cpp | 4 ++-- src/multimedia/platform/gstreamer/common/qgstpipeline_p.h | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/multimedia/platform/gstreamer/common/qgst_p.h b/src/multimedia/platform/gstreamer/common/qgst_p.h index 7e902c352..5b644bfda 100644 --- a/src/multimedia/platform/gstreamer/common/qgst_p.h +++ b/src/multimedia/platform/gstreamer/common/qgst_p.h @@ -298,6 +298,8 @@ public: } QGstObject &operator=(const QGstObject &other) { + if (this == &other) + return *this; if (other.m_object) gst_object_ref(other.m_object); if (m_object) @@ -305,7 +307,7 @@ public: m_object = other.m_object; return *this; } - ~QGstObject() { + virtual ~QGstObject() { if (m_object) gst_object_unref(m_object); } diff --git a/src/multimedia/platform/gstreamer/common/qgstpipeline.cpp b/src/multimedia/platform/gstreamer/common/qgstpipeline.cpp index 29fb0a552..1f20fe4ec 100644 --- a/src/multimedia/platform/gstreamer/common/qgstpipeline.cpp +++ b/src/multimedia/platform/gstreamer/common/qgstpipeline.cpp @@ -140,8 +140,6 @@ QGstPipelinePrivate::QGstPipelinePrivate(GstBus* bus, QObject* parent) : QObject(parent), m_bus(bus) { - gst_object_ref(GST_OBJECT(bus)); - // glib event loop can be disabled either by env variable or QT_NO_GLIB define, so check the dispacher QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher(); const bool hasGlib = dispatcher && dispatcher->inherits("QEventDispatcherGlib"); @@ -207,6 +205,8 @@ QGstPipeline::QGstPipeline(const QGstPipeline &o) QGstPipeline &QGstPipeline::operator=(const QGstPipeline &o) { + if (this == &o) + return *this; if (o.d) o.d->ref(); if (d) diff --git a/src/multimedia/platform/gstreamer/common/qgstpipeline_p.h b/src/multimedia/platform/gstreamer/common/qgstpipeline_p.h index 133fb167b..90d457ca2 100644 --- a/src/multimedia/platform/gstreamer/common/qgstpipeline_p.h +++ b/src/multimedia/platform/gstreamer/common/qgstpipeline_p.h @@ -84,7 +84,7 @@ public: QGstPipeline &operator=(const QGstPipeline &o); QGstPipeline(const char *name); QGstPipeline(GstPipeline *p); - ~QGstPipeline(); + ~QGstPipeline() override; // This is needed to help us avoid sending QVideoFrames or audio buffers to the // application while we're prerolling the pipeline. -- cgit v1.2.3