[libcamera-devel,v5] test: gstreamer: Fix the destructor of GstreamerTest base class
diff mbox series

Message ID 20210909131805.38786-1-vedantparanjape160201@gmail.com
State Accepted
Commit 0eea207b04ec2764fc4f2bafa1ec6df831a74573
Headers show
Series
  • [libcamera-devel,v5] test: gstreamer: Fix the destructor of GstreamerTest base class
Related show

Commit Message

Vedant Paranjape Sept. 9, 2021, 1:18 p.m. UTC
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@gmail.com>
Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 test/gstreamer/gstreamer_test.cpp | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Nicolas Dufresne Sept. 9, 2021, 4:28 p.m. UTC | #1
Le jeudi 09 septembre 2021 à 18:48 +0530, Vedant Paranjape a écrit :
> 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@gmail.com>
> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  test/gstreamer/gstreamer_test.cpp | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp
> index dbdcaec0b111..4171250584e6 100644
> --- a/test/gstreamer/gstreamer_test.cpp
> +++ b/test/gstreamer/gstreamer_test.cpp
> @@ -24,6 +24,7 @@ const char *__asan_default_options()
>  }
>  
>  GstreamerTest::GstreamerTest()
> +	: pipeline_(nullptr), libcameraSrc_(nullptr)

Good catch, you already got my R-b.

>  {
>  	/*
>  	* GStreamer by default spawns a process to run the
> @@ -69,12 +70,8 @@ GstreamerTest::GstreamerTest()
>  
>  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();
>  }

Patch
diff mbox series

diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp
index dbdcaec0b111..4171250584e6 100644
--- a/test/gstreamer/gstreamer_test.cpp
+++ b/test/gstreamer/gstreamer_test.cpp
@@ -24,6 +24,7 @@  const char *__asan_default_options()
 }
 
 GstreamerTest::GstreamerTest()
+	: pipeline_(nullptr), libcameraSrc_(nullptr)
 {
 	/*
 	* GStreamer by default spawns a process to run the
@@ -69,12 +70,8 @@  GstreamerTest::GstreamerTest()
 
 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();
 }