[libcamera-devel] [PATCH 1/1] qcam: Fix crash when switching from non existant camera

paul.elder at ideasonboard.com paul.elder at ideasonboard.com
Thu Sep 8 07:05:06 CEST 2022


On Wed, Sep 07, 2022 at 10:05:04PM +0530, Utkarsh Tiwari via libcamera-devel wrote:
> When switching to different camera we try to release the camera
> previously used. But if that camera has been unplugged, then its
> instance would have been destroyed. Accessing it leads to seg fault.
> 
> Fix by checking camera_ to see if it exists.
> 
> Bug: https://bugs.libcamera.org/show_bug.cgi?id=147
> Signed-off-by: Utkarsh Tiwari <utkarsh02t at gmail.com>

Reviewed-by: Paul Elder <paul.elder at ideasonboard.com>

> ---
>  src/qcam/main_window.cpp | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
> index 6fe36168..e0e5092e 100644
> --- a/src/qcam/main_window.cpp
> +++ b/src/qcam/main_window.cpp
> @@ -284,7 +284,9 @@ void MainWindow::switchCamera()
>  	 */
>  	startStopAction_->setChecked(false);
>  
> -	camera_->release();
> +	if (camera_)
> +		camera_->release();
> +
>  	camera_ = cam;
>  
>  	startStopAction_->setChecked(true);
> -- 
> 2.34.1
> 


More information about the libcamera-devel mailing list