From edbcdebba7602aeb30a12817088bbabbfc57c98b Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 21 Jan 2024 04:45:40 +0200 Subject: test: message: Destroy Object from correct thread context The MessageReceiver and RecursiveMessageReceiver used in the test are destroyed from the main thread, which is invalid for a thread-bound object bound to a different thread. Fix it by destroying them with deleteLater(). Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal --- test/message.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/message.cpp b/test/message.cpp index a34e0f0b..2f9f281c 100644 --- a/test/message.cpp +++ b/test/message.cpp @@ -109,16 +109,19 @@ protected: return TestFail; } - MessageReceiver receiver; - receiver.moveToThread(&thread_); + MessageReceiver *receiver = new MessageReceiver(); + receiver->moveToThread(&thread_); thread_.start(); - receiver.postMessage(std::make_unique(Message::None)); + receiver->postMessage(std::make_unique(Message::None)); this_thread::sleep_for(chrono::milliseconds(100)); - switch (receiver.status()) { + MessageReceiver::Status status = receiver->status(); + receiver->deleteLater(); + + switch (status) { case MessageReceiver::NoMessage: cout << "No message received" << endl; return TestFail; @@ -135,8 +138,7 @@ protected: * leaks. Two messages need to be posted to ensure we don't only * test the simple case of a queue containing a single message. */ - std::unique_ptr recursiveReceiver = - std::make_unique(); + RecursiveMessageReceiver *recursiveReceiver = new RecursiveMessageReceiver(); recursiveReceiver->moveToThread(&thread_); recursiveReceiver->postMessage(std::make_unique(Message::None)); @@ -144,7 +146,10 @@ protected: this_thread::sleep_for(chrono::milliseconds(10)); - if (!recursiveReceiver->success()) { + bool success = recursiveReceiver->success(); + recursiveReceiver->deleteLater(); + + if (!success) { cout << "Recursive message delivery failed" << endl; return TestFail; } -- cgit v1.2.1