Avoids PostTask to repost a repeated task.

There seems to be a race caused by the libevent wrapping TaskQueue
implementation when reposting a repeated task at destruction time. This
race results in the posted task being leaked according to asan.

Bug: webrtc:10278
Change-Id: Ida40b884547f3f789a804ca0ab3ce36982a4d68e
Reviewed-on: https://webrtc-review.googlesource.com/c/121424
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26839}
This commit is contained in:
Sebastian Jansson
2019-02-04 16:39:28 +01:00
committed by Commit Bot
parent ce7a4fb67b
commit a497d12a02
2 changed files with 9 additions and 10 deletions

View File

@ -38,12 +38,10 @@ bool RepeatingTaskBase::Run() {
TimeDelta lost_time = Timestamp::us(rtc::TimeMicros()) - next_run_time_;
next_run_time_ += delay;
delay -= lost_time;
delay = std::max(delay, TimeDelta::Zero());
task_queue_->PostDelayedTask(absl::WrapUnique(this), delay.ms());
if (delay <= TimeDelta::Zero()) {
task_queue_->PostTask(absl::WrapUnique(this));
} else {
task_queue_->PostDelayedTask(absl::WrapUnique(this), delay.ms());
}
// Return false to tell the TaskQueue to not destruct this object since we
// have taken ownership with absl::WrapUnique.
return false;