diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-01-19 03:43:55 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-01-25 02:39:20 +0200 |
commit | fdcea5ad7996f65848006e4df8ab75e20dbc0461 (patch) | |
tree | 45e70ccef9057d70701824b32005e763955cc5cf /test/timer-thread.cpp | |
parent | 4f76beae8612f02e086e96d79447b7e8984c8821 (diff) |
test: timer-thread: Destroy Object from correct thread context
The TimeoutHandler used in the test is destroyed from the main thread,
which is invalid for a thread-bound object bound to a different thread.
Fix it by destroying it with deleteLater().
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Diffstat (limited to 'test/timer-thread.cpp')
-rw-r--r-- | test/timer-thread.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/test/timer-thread.cpp b/test/timer-thread.cpp index 4caf4e33..8675e248 100644 --- a/test/timer-thread.cpp +++ b/test/timer-thread.cpp @@ -50,7 +50,9 @@ protected: int init() { thread_.start(); - timeout_.moveToThread(&thread_); + + timeout_ = new TimeoutHandler(); + timeout_->moveToThread(&thread_); return TestPass; } @@ -63,7 +65,7 @@ protected: */ this_thread::sleep_for(chrono::milliseconds(200)); - if (!timeout_.timeout()) { + if (!timeout_->timeout()) { cout << "Timer expiration test failed" << endl; return TestFail; } @@ -73,13 +75,17 @@ protected: void cleanup() { - /* Must stop thread before destroying timeout. */ + /* + * Object class instances must be destroyed from the thread + * they live in. + */ + timeout_->deleteLater(); thread_.exit(0); thread_.wait(); } private: - TimeoutHandler timeout_; + TimeoutHandler *timeout_; Thread thread_; }; |