{"id":19428,"url":"https://patchwork.libcamera.org/api/1.1/patches/19428/?format=json","web_url":"https://patchwork.libcamera.org/patch/19428/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20240121035948.4226-8-laurent.pinchart@ideasonboard.com>","date":"2024-01-21T03:59:43","name":"[libcamera-devel,07/12] test: message: Destroy Object from correct thread context","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"601fb7aa285a59c28712b3cc91aa9c5a09e62a95","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19428/mbox/","series":[{"id":4149,"url":"https://patchwork.libcamera.org/api/1.1/series/4149/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4149","date":"2024-01-21T03:59:36","name":"libcamera: Hardening against thread race conditions","version":1,"mbox":"https://patchwork.libcamera.org/series/4149/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19428/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19428/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 E24C3C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 21 Jan 2024 03:59:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8486C6294F;\n\tSun, 21 Jan 2024 04:59:58 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3FE0962931\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 21 Jan 2024 04:59:55 +0100 (CET)","from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi\n\t[89.27.53.110])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3F4521574;\n\tSun, 21 Jan 2024 04:58:43 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1705809598;\n\tbh=KC/mNBwsTvo7jbNoWkM9MEDV6p6gdf3XmassPtSI1BY=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=20HNywIfbZGB/d7nREhT/oNCkqMVORoaK2SyTeczMzQ43pDbpqdGSm1nQbNfdV7F/\n\t+YkT+jMVeLEVustz42KtkLQ8dXlNOf+uDrSOr4/2c0tBrcuaDkfQpA3XdgK/aDmmu+\n\tFQacjdJL+HW++Bbwj+8JL0V1LGhcVQDlgPSgW4YJOAtclZSGwDwJn0D00QPcoCSUse\n\tYzMYy1srmq7aatdEmAI/1Q4X63Y8IOI2Gx1daUQRlz2j9T7zMBbd9PWNJPVDfWGmwI\n\tYqHeDr3w9KRq4PTA4ozDXa6Y+bDjLF47DT3PTkohY731WbieOnIGSN9zwY3TSneS8d\n\tAngThxzlvwGMQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1705809523;\n\tbh=KC/mNBwsTvo7jbNoWkM9MEDV6p6gdf3XmassPtSI1BY=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=SKgxIdYPo4SZDENA8F2UWmFt+5tji5rFzSQTSKx7oTcg3Kh1eAW1dltFZ+wpKmaij\n\tvfIxcZ16uyy5n4gbDjsOSmoRLTumj9d9MOpUU3iTnRGbX81Otqz+6ZE4o/qpXdjB5+\n\trOGp0Zr2VMxR4skQrZb82hZjoL35oIfc/t+crsK8="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"SKgxIdYP\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Sun, 21 Jan 2024 05:59:43 +0200","Message-ID":"<20240121035948.4226-8-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20240121035948.4226-1-laurent.pinchart@ideasonboard.com>","References":"<20240121035948.4226-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 07/12] test: message: Destroy Object from\n\tcorrect thread context","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The MessageReceiver and RecursiveMessageReceiver used in the test are\ndestroyed from the main thread, which is invalid for a thread-bound\nobject bound to a different thread. Fix it by destroying them with\ndeleteLater().\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n test/message.cpp | 19 ++++++++++++-------\n 1 file changed, 12 insertions(+), 7 deletions(-)","diff":"diff --git a/test/message.cpp b/test/message.cpp\nindex a34e0f0b5e10..2f9f281c5101 100644\n--- a/test/message.cpp\n+++ b/test/message.cpp\n@@ -109,16 +109,19 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tMessageReceiver receiver;\n-\t\treceiver.moveToThread(&thread_);\n+\t\tMessageReceiver *receiver = new MessageReceiver();\n+\t\treceiver->moveToThread(&thread_);\n \n \t\tthread_.start();\n \n-\t\treceiver.postMessage(std::make_unique<Message>(Message::None));\n+\t\treceiver->postMessage(std::make_unique<Message>(Message::None));\n \n \t\tthis_thread::sleep_for(chrono::milliseconds(100));\n \n-\t\tswitch (receiver.status()) {\n+\t\tMessageReceiver::Status status = receiver->status();\n+\t\treceiver->deleteLater();\n+\n+\t\tswitch (status) {\n \t\tcase MessageReceiver::NoMessage:\n \t\t\tcout << \"No message received\" << endl;\n \t\t\treturn TestFail;\n@@ -135,8 +138,7 @@ protected:\n \t\t * leaks. Two messages need to be posted to ensure we don't only\n \t\t * test the simple case of a queue containing a single message.\n \t\t */\n-\t\tstd::unique_ptr<RecursiveMessageReceiver> recursiveReceiver =\n-\t\t\tstd::make_unique<RecursiveMessageReceiver>();\n+\t\tRecursiveMessageReceiver *recursiveReceiver = new RecursiveMessageReceiver();\n \t\trecursiveReceiver->moveToThread(&thread_);\n \n \t\trecursiveReceiver->postMessage(std::make_unique<Message>(Message::None));\n@@ -144,7 +146,10 @@ protected:\n \n \t\tthis_thread::sleep_for(chrono::milliseconds(10));\n \n-\t\tif (!recursiveReceiver->success()) {\n+\t\tbool success = recursiveReceiver->success();\n+\t\trecursiveReceiver->deleteLater();\n+\n+\t\tif (!success) {\n \t\t\tcout << \"Recursive message delivery failed\" << endl;\n \t\t\treturn TestFail;\n \t\t}\n","prefixes":["libcamera-devel","07/12"]}