[libcamera-devel] [PATCH v4] test: gstreamer: Fix the destructor of GstreamerTest base class

Vedant Paranjape vedantparanjape160201 at gmail.com
Thu Sep 9 15:07:33 CEST 2021


The destructor tried to check if pipeline_ is a parent of libcameraSrc_.
This was needed to be checked as if it is, cleanup of libcameraSrc_
would be handled by pipeline itself.

Since, the destructor can be called anytime, even when pipeline_ hasn't
been created, the use of pipeline_ to check if libcameraSrc_ has an
ancestor as pipeline_ caused a segmentation fault.

Fixes: f58768092277 ("test: gstreamer: Fix the destructor of GstreamerTest base class")
Signed-off-by: Vedant Paranjape <vedantparanjape160201 at gmail.com>
Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois at ideasonboard.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne at collabora.com>
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
 test/gstreamer/gstreamer_test.cpp | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp
index dbdcaec0b111..7dcb3c5c2869 100644
--- a/test/gstreamer/gstreamer_test.cpp
+++ b/test/gstreamer/gstreamer_test.cpp
@@ -64,17 +64,16 @@ GstreamerTest::GstreamerTest()
 		return;
 	}
 
+	pipeline_ = nullptr;
+	libcameraSrc_ = nullptr;
+
 	status_ = TestPass;
 }
 
 GstreamerTest::~GstreamerTest()
 {
-	if (libcameraSrc_ &&
-	    !gst_object_has_as_ancestor(GST_OBJECT(libcameraSrc_),
-					GST_OBJECT(pipeline_)))
-		gst_object_unref(libcameraSrc_);
-	if (pipeline_)
-		gst_object_unref(pipeline_);
+	g_clear_object(&pipeline_);
+	g_clear_object(&libcameraSrc_);
 
 	gst_deinit();
 }
-- 
2.25.1



More information about the libcamera-devel mailing list