[libcamera-devel] [PATCH 2/2] test: gstreamer_single_stream_test: Fix memory leak

Nicolas Dufresne nicolas at ndufresne.ca
Tue Sep 14 19:45:49 CEST 2021


Le mardi 14 septembre 2021 à 17:47 +0530, Umang Jain a écrit :
> The test hold a valid reference to convert0_ and sink0_ but
> not released. This results in a memory leak and can be checked
> via valgrind. Drop the references with test cleanup() virtual
> function.
> 
> Valgrind log:
> ==95352==    definitely lost: 1,688 bytes in 2 blocks
> ==95352==    indirectly lost: 11,901 bytes in 37 blocks
> 
> The patch fixes the leaks reported by valgrind above to:
> ==120397==    definitely lost: 0 bytes in 0 blocks
> ==120397==    indirectly lost: 0 bytes in 0 blocks
> 
> Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
> ---
>  test/gstreamer/gstreamer_single_stream_test.cpp | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp
> index d992455c..763a77b1 100644
> --- a/test/gstreamer/gstreamer_single_stream_test.cpp
> +++ b/test/gstreamer/gstreamer_single_stream_test.cpp
> @@ -70,6 +70,12 @@ protected:
>  		return TestPass;
>  	}
>  
> +	void cleanup() override
> +	{
> +		gst_object_unref(convert0_);
> +		gst_object_unref(sink0_);
> +	}

This is correct of course, but I think we could cleanup more the test. With a
run/cleanup() set of function, I would expect to be able to loop over and run
the test multiple times, but it does not seem to be the case due to the fact the
pipeline is not fully constructed in run().

For the leak being fixed:
Reviewed-by: Nicolas Dufresne <nicolas.dufresne at collabora.com>

> +
>  private:
>  	GstElement *convert0_;
>  	GstElement *sink0_;




More information about the libcamera-devel mailing list