Ensure task queues delete closures in task queue context.
Bug: webrtc:14449
Change-Id: I90d09d35398c1f8817701662f51cbc6a684a2fe0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/275773
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38917}
diff --git a/rtc_base/task_queue_win.cc b/rtc_base/task_queue_win.cc
index bb8e522..9ea7fc6 100644
--- a/rtc_base/task_queue_win.cc
+++ b/rtc_base/task_queue_win.cc
@@ -290,6 +290,18 @@
RunPendingTasks();
}
}
+ // Ensure remaining deleted tasks are destroyed with Current() set up to this
+ // task queue.
+ std::queue<absl::AnyInvocable<void() &&>> pending;
+ {
+ MutexLock lock(&pending_lock_);
+ pending_.swap(pending);
+ }
+ pending = {};
+#if RTC_DCHECK_IS_ON
+ MutexLock lock(&pending_lock_);
+ RTC_DCHECK(pending_.empty());
+#endif
}
bool TaskQueueWin::ProcessQueuedMessages() {