From b42659eb8baa384e329e6af6afea89bb4005fb46 Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Fri, 27 Oct 2017 14:20:51 +0200 Subject: Gstreamer: Fix memory leak in CameraBinSession Created GstElement objects m_cameraSrc and m_videoSrc should be unrefed. Task-number: QTBUG-53204 Change-Id: Ibbfd37d928fe87ea899549da7c12fa2386e214cc Reviewed-by: Christian Stromme --- src/plugins/gstreamer/camerabin/camerabinsession.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/plugins/gstreamer/camerabin/camerabinsession.cpp') diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp index ab0bea24a..4941c6ef6 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinsession.cpp @@ -212,6 +212,12 @@ CameraBinSession::~CameraBinSession() if (m_sourceFactory) gst_object_unref(GST_OBJECT(m_sourceFactory)); + + if (m_cameraSrc) + gst_object_unref(GST_OBJECT(m_cameraSrc)); + + if (m_videoSrc) + gst_object_unref(GST_OBJECT(m_videoSrc)); } #if QT_CONFIG(gstreamer_photography) @@ -538,11 +544,12 @@ GstElement *CameraBinSession::buildCameraSource() } } - if (m_cameraSrc != camSrc) + if (m_cameraSrc != camSrc) { g_object_set(G_OBJECT(m_camerabin), CAMERA_SOURCE_PROPERTY, m_cameraSrc, NULL); - - if (camSrc) - gst_object_unref(GST_OBJECT(camSrc)); + // Unref only if camSrc is not m_cameraSrc to prevent double unrefing. + if (camSrc) + gst_object_unref(GST_OBJECT(camSrc)); + } return m_cameraSrc; } -- cgit v1.2.3