[libcamera-devel] [PATCH 12/14] android: camera_hal_manager: Clean up resources when terminating

Jacopo Mondi jacopo at jmondi.org
Mon Aug 19 11:23:57 CEST 2019


Hi Laurent

On Sun, Aug 18, 2019 at 04:13:27AM +0300, Laurent Pinchart wrote:
> The CameraHalManager starts the libcamera CameraManager and creates
> CameraProxy instances for each camera in the system. Clean up those
> resources when the CameraHalManager terminates.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> ---
>  src/android/camera_hal_manager.cpp | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp
> index a1ffb3713d7e..cf981720bca4 100644
> --- a/src/android/camera_hal_manager.cpp
> +++ b/src/android/camera_hal_manager.cpp
> @@ -90,6 +90,10 @@ void CameraHalManager::run()
>
>  	/* Now start processing events and messages. */
>  	exec();
> +
> +	/* Clean up the resources we have allocated. */
> +	proxies_.clear();

Proxies are unique_ptr
	std::vector<std::unique_ptr<CameraProxy>> proxies_;

and they are unique_ptr so that they should be deleted at
CameraHalManager deletion time. However, the CameraHalManager instance
is defined as a static one in camera3_hal.cpp and the destructor of
the static instance should be called at library teardown time. However
I noticed with the help of valgrind the proxies memory did not get
released properly (according to valgrind, which might fail to detect
deletion after the library as been unloaded). So if you recall, I
tried to address this with __attribute((destructor)) withtout seeing
any change.

With your change, which I think is good, I guess proxies_ can now be
made a vector of plain pointers, doesn't it?

Thanks
  j



> +	cameraManager_->stop();
>  }
>
>  CameraProxy *CameraHalManager::open(unsigned int id,
> --
> Regards,
>
> Laurent Pinchart
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20190819/66ae3dda/attachment.sig>


More information about the libcamera-devel mailing list