Commit 61d6143a authored by Igor Zinkovsky's avatar Igor Zinkovsky Committed by Facebook Github Bot

fix use-after-free in addFunctionOnce

Summary: see title

Reviewed By: meyering

Differential Revision: D4441266

fbshipit-source-id: 4a8f589e2995a463e54b3979035a623824acf39e
parent dd5a72f2
...@@ -445,6 +445,7 @@ void FunctionScheduler::runOneFunction(std::unique_lock<std::mutex>& lock, ...@@ -445,6 +445,7 @@ void FunctionScheduler::runOneFunction(std::unique_lock<std::mutex>& lock,
} }
if (currentFunction_->runOnce) { if (currentFunction_->runOnce) {
// Don't reschedule if the function only needed to run once. // Don't reschedule if the function only needed to run once.
currentFunction_ = nullptr;
return; return;
} }
// Clear currentFunction_ // Clear currentFunction_
......
...@@ -456,6 +456,13 @@ TEST(FunctionScheduler, AddWithRunOnce) { ...@@ -456,6 +456,13 @@ TEST(FunctionScheduler, AddWithRunOnce) {
EXPECT_EQ(2, total); EXPECT_EQ(2, total);
delay(2); delay(2);
EXPECT_EQ(2, total); EXPECT_EQ(2, total);
fs.addFunctionOnce([&] { total += 2; }, "add2");
delay(1);
EXPECT_EQ(4, total);
delay(2);
EXPECT_EQ(4, total);
fs.shutdown(); fs.shutdown();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment