From patchwork Sun Apr 26 22:31:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3551 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F6EB603FA for ; Mon, 27 Apr 2020 00:31:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="QMkrUAoy"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0E9424F7 for ; Mon, 27 Apr 2020 00:31:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1587940305; bh=IU/1UKaPPOxhtAjLrX9XXbJJe7QWeMJftaZuD11jRzg=; h=From:To:Subject:Date:From; b=QMkrUAoyiEZa+xMMdlveM8WHcxGqpU+5WT/tDdS8l/LwoAUGpPuH3pU7SRSnkmnru LAHlweixgAc4Kr175TCjO29rRx9kmZz+xQcmivYXWUDCucJQM2uCvtV9RwUjUozAYl yvJJiWHXK1aPhHbNxXyD3/mkw4GJkSBcO3mfLa3M= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Apr 2020 01:31:26 +0300 Message-Id: <20200426223126.17943-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] qcam: Don't crash if camera can't be opened X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Apr 2020 22:31:45 -0000 If the camera specified on the command line can't be opened, the MainWindow constructor still proceeds to check the startStopAction_, which results in MainWindow::startCapture() being called and trying to use a null camera_ object. Fix this by returning from the constructor as soon as the error is detected. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain --- 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 cf39ed7aceca..ed0cad417d62 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -70,8 +70,10 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options) /* Open the camera and start capture. */ ret = openCamera(); - if (ret < 0) + if (ret < 0) { quit(); + return; + } startStopAction_->setChecked(true); }