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

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

Commit Message

Vedant Paranjape Sept. 8, 2021, 1:57 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>
---
 test/gstreamer/gstreamer_test.cpp | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Jean-Michel Hautbois Sept. 8, 2021, 2:12 p.m. UTC | #1
Hi Vedant,

On 08/09/2021 15:57, Vedant Paranjape wrote:
> 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>
> ---
>  test/gstreamer/gstreamer_test.cpp | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp
> index dbdcaec0b111..e0f8de29cbd2 100644
> --- a/test/gstreamer/gstreamer_test.cpp
> +++ b/test/gstreamer/gstreamer_test.cpp
> @@ -69,12 +69,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_);
> +	gst_clear_object(&pipeline_);
> +	gst_clear_object(&libcameraSrc_);

According to the GStreamer documentation[0], gst_clear_object is only
supported since 1.16 and libcamera currently requires 1.14.

You can use g_clear_object, the effect will be the same.

Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>

[0]
https://gstreamer.freedesktop.org/documentation/gstreamer/gstobject.html?gi-language=c#gst_clear_object



>  
>  	gst_deinit();
>  }
>
Vedant Paranjape Sept. 8, 2021, 2:15 p.m. UTC | #2
Hi Jean-Michel,
I am sending v4 with a fix.

On Wed, 8 Sep, 2021, 19:42 Jean-Michel Hautbois, <
jeanmichel.hautbois@ideasonboard.com> wrote:

> Hi Vedant,
>
> On 08/09/2021 15:57, Vedant Paranjape wrote:
> > 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>
> > ---
> >  test/gstreamer/gstreamer_test.cpp | 8 ++------
> >  1 file changed, 2 insertions(+), 6 deletions(-)
> >
> > diff --git a/test/gstreamer/gstreamer_test.cpp
> b/test/gstreamer/gstreamer_test.cpp
> > index dbdcaec0b111..e0f8de29cbd2 100644
> > --- a/test/gstreamer/gstreamer_test.cpp
> > +++ b/test/gstreamer/gstreamer_test.cpp
> > @@ -69,12 +69,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_);
> > +     gst_clear_object(&pipeline_);
> > +     gst_clear_object(&libcameraSrc_);
>
> According to the GStreamer documentation[0], gst_clear_object is only
> supported since 1.16 and libcamera currently requires 1.14.
>
> You can use g_clear_object, the effect will be the same.
>
> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
>
> [0]
>
> https://gstreamer.freedesktop.org/documentation/gstreamer/gstobject.html?gi-language=c#gst_clear_object
>
>
>
> >
> >       gst_deinit();
> >  }
> >
>

Patch
diff mbox series

diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp
index dbdcaec0b111..e0f8de29cbd2 100644
--- a/test/gstreamer/gstreamer_test.cpp
+++ b/test/gstreamer/gstreamer_test.cpp
@@ -69,12 +69,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_);
+	gst_clear_object(&pipeline_);
+	gst_clear_object(&libcameraSrc_);
 
 	gst_deinit();
 }