From patchwork Mon Sep 23 13:22:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1992 Return-Path: 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 4049660BB0 for ; Mon, 23 Sep 2019 15:22:37 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B009653B; Mon, 23 Sep 2019 15:22:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1569244956; bh=OR/ng4fajGUOo0ZnJnHVDtOC4055fCBL33kuXRuCqcE=; h=From:To:Cc:Subject:Date:From; b=MZCfKlTdFTSfif8+kuA0zww6PcoznqbTUW/bdv33HJyqs+509m6BTp7Nn88Lh04Je rUvTEfusTLA8NNbz6tgxW0xH7JSiJNva9tREi7aDXmBsl9in9b6Q+5O0xqPs/WZiKk NA0iPlmofuZmikN6bs50DgQ/CS10SbO1FAoPyHas= From: Kieran Bingham To: LibCamera Devel Date: Mon, 23 Sep 2019 14:22:29 +0100 Message-Id: <20190923132229.17027-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] qcam: Fix ViewFinder memory leak X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Sep 2019 13:22:37 -0000 When setting the format on the ViewFinder, a new image_ is allocated. Any change in format deletes the existing allocation, but it is not cleaned up on shutdown: Direct leak of 32 byte(s) in 1 object(s) allocated from: #0 0x7f0bf8a7e17f in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10e17f) #1 0x564c7205f7b0 in ViewFinder::setFormat(unsigned int, unsigned int, unsigned int) ../src/qcam/viewfinder.cpp:43 #2 0x564c71fec467 in MainWindow::startCapture() ../src/qcam/main_window.cpp:152 #3 0x564c71fe6c1a in MainWindow::MainWindow(libcamera::CameraManager*, OptionsParser::Options const&) ../src/qcam/main_window.cpp:40 #4 0x564c71fdf133 in main ../src/qcam/main.cpp:76 #5 0x7f0bf5944b6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a) Provide a ViewFinder destructor, and delete the allocation as appropriate. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/qcam/viewfinder.cpp | 5 +++++ src/qcam/viewfinder.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp index 224a227ddd5b..98a8ab68e5f6 100644 --- a/src/qcam/viewfinder.cpp +++ b/src/qcam/viewfinder.cpp @@ -16,6 +16,11 @@ ViewFinder::ViewFinder(QWidget *parent) { } +ViewFinder::~ViewFinder() +{ + delete image_; +} + void ViewFinder::display(const unsigned char *raw, size_t size) { converter_.convert(raw, size, image_); diff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h index c9ca98913e05..33bdb1460f84 100644 --- a/src/qcam/viewfinder.h +++ b/src/qcam/viewfinder.h @@ -17,6 +17,7 @@ class ViewFinder : public QLabel { public: ViewFinder(QWidget *parent); + ~ViewFinder(); int setFormat(unsigned int format, unsigned int width, unsigned int height);