From patchwork Thu Sep 23 11:54:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13909 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id ED4DBBF01C for ; Thu, 23 Sep 2021 11:54:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A9EB76918A; Thu, 23 Sep 2021 13:54:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="H9AjODDR"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1719269189 for ; Thu, 23 Sep 2021 13:54:47 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AB14045E for ; Thu, 23 Sep 2021 13:54:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1632398086; bh=yz1ytDSKp5kGeo3AU3ma8lLSG8xwLDCUc4y0R3PVhTY=; h=From:To:Subject:Date:From; b=H9AjODDRTlxa0EB4FiKmRgoF/D1UGzUTiEGkfYHIKcgqUlLnjP3PPgVmMu5lfCjns i4uWdHVcHW7wo14kuHb37vbfmKISFXjdAEBk/nULOdufU8As+aL0g/IcjGPh8Yp9D1 F9twn/+rN/RtWIfLw1M6LE8PrPAYNSo42/JfIfWw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 23 Sep 2021 14:54:39 +0300 Message-Id: <20210923115439.30863-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] android: camera_device: Return unique_ptr from createFrameBuffer 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Returning a non-managed pointer can cause leaks. Use a unique_ptr<> instead to avoid possible future issues. The std::move() for the planes argument to the FrameBuffer constructor is dropped as it's misleading. FrameBuffer has no constructor that takes an rvalue reference to planes, so the vector was copied despite the move. This only clarifies the intent, no functional change is introduced. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Hirokazu Honda Reviewed-by: Umang Jain Reviewed-by: Paul Elder --- src/android/camera_device.cpp | 18 ++++++++++-------- src/android/camera_device.h | 7 ++++--- 2 files changed, 14 insertions(+), 11 deletions(-) base-commit: 2cc4303b172a76ac5b431c4fb4df8a083f7d3fcf diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index a693dcbe89f4..21844e5114a9 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -774,9 +774,9 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return 0; } -FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer, - PixelFormat pixelFormat, - const Size &size) +std::unique_ptr +CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer, + PixelFormat pixelFormat, const Size &size) { CameraBuffer buf(camera3buffer, pixelFormat, size, PROT_READ); if (!buf.isValid()) { @@ -797,7 +797,7 @@ FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer planes[i].length = buf.size(i); } - return new FrameBuffer(std::move(planes)); + return std::make_unique(planes); } int CameraDevice::processControls(Camera3RequestDescriptor *descriptor) @@ -1002,10 +1002,12 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * associate it with the Camera3RequestDescriptor for * lifetime management only. */ - buffer = createFrameBuffer(*camera3Buffer.buffer, - cameraStream->configuration().pixelFormat, - cameraStream->configuration().size); - descriptor.frameBuffers_.emplace_back(buffer); + descriptor.frameBuffers_.push_back( + createFrameBuffer(*camera3Buffer.buffer, + cameraStream->configuration().pixelFormat, + cameraStream->configuration().size)); + + buffer = descriptor.frameBuffers_.back().get(); LOG(HAL, Debug) << ss.str() << " (direct)"; break; diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 296c2f185e4e..43eb5895ba64 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -94,9 +94,10 @@ private: void stop(); - libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer, - libcamera::PixelFormat pixelFormat, - const libcamera::Size &size); + std::unique_ptr + createFrameBuffer(const buffer_handle_t camera3buffer, + libcamera::PixelFormat pixelFormat, + const libcamera::Size &size); void abortRequest(camera3_capture_request_t *request); bool isValidRequest(camera3_capture_request_t *request) const; void notifyShutter(uint32_t frameNumber, uint64_t timestamp);