Skip to content

Commit ce612f1

Browse files
committed
Merge #9186: test: Fix use-after-free in scheduler tests
12519bf test: Fix use-after-free in scheduler tests (Wladimir J. van der Laan)
2 parents 9346f84 + 12519bf commit ce612f1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/scheduler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ void CScheduler::serviceQueue()
5454
#else
5555
// Some boost versions have a conflicting overload of wait_until that returns void.
5656
// Explicitly use a template here to avoid hitting that overload.
57-
while (!shouldStop() && !taskQueue.empty() &&
58-
newTaskScheduled.wait_until<>(lock, taskQueue.begin()->first) != boost::cv_status::timeout) {
59-
// Keep waiting until timeout
57+
while (!shouldStop() && !taskQueue.empty()) {
58+
boost::chrono::system_clock::time_point timeToWaitFor = taskQueue.begin()->first;
59+
if (newTaskScheduled.wait_until<>(lock, timeToWaitFor) == boost::cv_status::timeout)
60+
break; // Exit loop after timeout, it means we reached the time of the event
6061
}
6162
#endif
6263
// If there are multiple threads, the queue can empty while we're waiting (another

0 commit comments

Comments
 (0)