From patchwork Sun Apr 11 21:36:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11887 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 2070CBD224 for ; Sun, 11 Apr 2021 21:37:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 585F7687F5; Sun, 11 Apr 2021 23:37:02 +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="n/qq5jGk"; 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 86F20687F4 for ; Sun, 11 Apr 2021 23:37:00 +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 0239F40A for ; Sun, 11 Apr 2021 23:36:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1618177020; bh=GddMDB6JYhx1E7O2Y2xA4We+fASiUWgG8boodz6uQ38=; h=From:To:Subject:Date:From; b=n/qq5jGk39N/c0YwfR2Y6yOacPSGl7QyA+zfF4e3zN+KkddOzTersztJSjShuKvI9 sHNuIuu9ieuk4/1nuVp2AfRHTtaKfFmEE8uvk2n59s12KU8OybVN6OlrOUSZZgBNIi 4IMCY8fRLWGQoZ88JhZ9Yu31DcavQB0F1LtF8oxY= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 12 Apr 2021 00:36:07 +0300 Message-Id: <20210411213607.9451-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] test: threads: Fix memory leak 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" The last instance of Thread allocated in the test is never deleted, not are other instances deleted in error paths. Use a std::unique_ptr<> to ensure deletion. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Tested-by: Sebastian Fricke --- test/threads.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/test/threads.cpp b/test/threads.cpp index b4b8d913cd2b..e0c50dc90a65 100644 --- a/test/threads.cpp +++ b/test/threads.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include "libcamera/internal/thread.h" @@ -45,23 +46,23 @@ protected: int run() { /* Test Thread() retrieval for the main thread. */ - Thread *thread = Thread::current(); - if (!thread) { + Thread *mainThread = Thread::current(); + if (!mainThread) { cout << "Thread::current() failed to main thread" << endl; return TestFail; } - if (!thread->isRunning()) { + if (!mainThread->isRunning()) { cout << "Main thread is not running" << endl; return TestFail; } /* Test starting the main thread, the test shall not crash. */ - thread->start(); + mainThread->start(); /* Test the running state of a custom thread. */ - thread = new Thread(); + std::unique_ptr thread = std::make_unique(); thread->start(); if (!thread->isRunning()) { @@ -79,10 +80,8 @@ protected: return TestFail; } - delete thread; - /* Test waiting for completion with a timeout. */ - thread = new DelayThread(chrono::milliseconds(500)); + thread = std::make_unique(chrono::milliseconds(500)); thread->start(); thread->exit(0); @@ -100,10 +99,8 @@ protected: return TestFail; } - delete thread; - /* Test waiting on a thread that isn't running. */ - thread = new Thread(); + thread = std::make_unique(); timeout = !thread->wait(); if (timeout) {