From ebab912fb6d4c8d505f2bd54ebc84c7525da31ca Mon Sep 17 00:00:00 2001 From: Nick Bourdakos Date: Tue, 9 May 2023 10:13:47 -0700 Subject: [PATCH] Fix heap-use-after-free issue in fake timer PiperOrigin-RevId: 530644090 --- internal/test/fake_timer.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/test/fake_timer.cc b/internal/test/fake_timer.cc index afc9a86b..2bbe3b7f 100644 --- a/internal/test/fake_timer.cc +++ b/internal/test/fake_timer.cc @@ -65,7 +65,9 @@ void FakeTimer::ClockUpdated() { if (duration >= delay_ && fired_count_ == 0) { ++fired_count_; - callback_(); + if (callback_ != nullptr) { + callback_(); + } } if (period_ == 0 || duration < delay_ || @@ -77,7 +79,9 @@ void FakeTimer::ClockUpdated() { int should_fire_count = count - fired_count_ + 1; for (int i = 0; i < should_fire_count; ++i) { ++fired_count_; - callback_(); + if (callback_ != nullptr) { + callback_(); + } } }