[libcamera-devel] [PATCH] tests: call the derived Test class cleanup() function

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri Dec 21 05:42:20 CET 2018


Hi Niklas,

Thank you for the patch.

On Friday, 21 December 2018 02:53:29 EET Niklas Söderlund wrote:
> Calling the cleanup() function in the base class Test destructor only
> calls the base class empty cleanup() function, not the overloaded one.
> This results in tests not cleaning up after themself. Solve this by
> explicitly calling the cleanup() function from execute().
> 
> This was discovered while running valgrind on tests where objects where
> allocated in init() and freed in cleanup().

My bad :-/

Destructors must never call virtual methods, as during the execution of a 
destructor the object behaves as if its dynamic type was identical to the 
static type of the destructor. The reason is simple : destructors are called 
in sequence from the leaf class to the root class. The Test destructor thus 
can access any member of a derive class, as it will already have been 
destructed.

> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>

Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

> ---
>  test/test.cpp | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/test/test.cpp b/test/test.cpp
> index 4e7779e750d56687..1bb6ebcb9e8acf18 100644
> --- a/test/test.cpp
> +++ b/test/test.cpp
> @@ -13,7 +13,6 @@ Test::Test()
> 
>  Test::~Test()
>  {
> -	cleanup();
>  }
> 
>  int Test::execute()
> @@ -24,5 +23,9 @@ int Test::execute()
>  	if (ret < 0)
>  		return ret;
> 
> -	return run();
> +	ret = run();
> +
> +	cleanup();
> +
> +	return ret;
>  }

-- 
Regards,

Laurent Pinchart





More information about the libcamera-devel mailing list