{"id":11887,"url":"https://patchwork.libcamera.org/api/patches/11887/?format=json","web_url":"https://patchwork.libcamera.org/patch/11887/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210411213607.9451-1-laurent.pinchart@ideasonboard.com>","date":"2021-04-11T21:36:07","name":"[libcamera-devel] test: threads: Fix memory leak","commit_ref":"05b80226010bef5d296ed8331a0582a6e045a4ae","pull_url":null,"state":"accepted","archived":false,"hash":"a192731112d00265ceff8cd5448bf1c8fbb50aee","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11887/mbox/","series":[{"id":1910,"url":"https://patchwork.libcamera.org/api/series/1910/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1910","date":"2021-04-11T21:36:07","name":"[libcamera-devel] test: threads: Fix memory leak","version":1,"mbox":"https://patchwork.libcamera.org/series/1910/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11887/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11887/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2070CBD224\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 11 Apr 2021 21:37:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 585F7687F5;\n\tSun, 11 Apr 2021 23:37:02 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 86F20687F4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 11 Apr 2021 23:37:00 +0200 (CEST)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0239F40A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 11 Apr 2021 23:36:59 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"n/qq5jGk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1618177020;\n\tbh=GddMDB6JYhx1E7O2Y2xA4We+fASiUWgG8boodz6uQ38=;\n\th=From:To:Subject:Date:From;\n\tb=n/qq5jGk39N/c0YwfR2Y6yOacPSGl7QyA+zfF4e3zN+KkddOzTersztJSjShuKvI9\n\tsHNuIuu9ieuk4/1nuVp2AfRHTtaKfFmEE8uvk2n59s12KU8OybVN6OlrOUSZZgBNIi\n\t4IMCY8fRLWGQoZ88JhZ9Yu31DcavQB0F1LtF8oxY=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","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":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The last instance of Thread allocated in the test is never deleted, not\nare other instances deleted in error paths. Use a std::unique_ptr<> to\nensure deletion.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n test/threads.cpp | 19 ++++++++-----------\n 1 file changed, 8 insertions(+), 11 deletions(-)","diff":"diff --git a/test/threads.cpp b/test/threads.cpp\nindex b4b8d913cd2b..e0c50dc90a65 100644\n--- a/test/threads.cpp\n+++ b/test/threads.cpp\n@@ -7,6 +7,7 @@\n \n #include <chrono>\n #include <iostream>\n+#include <memory>\n #include <thread>\n \n #include \"libcamera/internal/thread.h\"\n@@ -45,23 +46,23 @@ protected:\n \tint run()\n \t{\n \t\t/* Test Thread() retrieval for the main thread. */\n-\t\tThread *thread = Thread::current();\n-\t\tif (!thread) {\n+\t\tThread *mainThread = Thread::current();\n+\t\tif (!mainThread) {\n \t\t\tcout << \"Thread::current() failed to main thread\"\n \t\t\t     << endl;\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (!thread->isRunning()) {\n+\t\tif (!mainThread->isRunning()) {\n \t\t\tcout << \"Main thread is not running\" << endl;\n \t\t\treturn TestFail;\n \t\t}\n \n \t\t/* Test starting the main thread, the test shall not crash. */\n-\t\tthread->start();\n+\t\tmainThread->start();\n \n \t\t/* Test the running state of a custom thread. */\n-\t\tthread = new Thread();\n+\t\tstd::unique_ptr<Thread> thread = std::make_unique<Thread>();\n \t\tthread->start();\n \n \t\tif (!thread->isRunning()) {\n@@ -79,10 +80,8 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tdelete thread;\n-\n \t\t/* Test waiting for completion with a timeout. */\n-\t\tthread = new DelayThread(chrono::milliseconds(500));\n+\t\tthread = std::make_unique<DelayThread>(chrono::milliseconds(500));\n \t\tthread->start();\n \t\tthread->exit(0);\n \n@@ -100,10 +99,8 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tdelete thread;\n-\n \t\t/* Test waiting on a thread that isn't running. */\n-\t\tthread = new Thread();\n+\t\tthread = std::make_unique<Thread>();\n \n \t\ttimeout = !thread->wait();\n \t\tif (timeout) {\n","prefixes":["libcamera-devel"]}