Skip to content

Commit

Permalink
fix use-after-free in addFunctionOnce
Browse files Browse the repository at this point in the history
Summary: see title

Reviewed By: meyering

Differential Revision: D4441266

fbshipit-source-id: 4a8f589e2995a463e54b3979035a623824acf39e
  • Loading branch information
Igor Zinkovsky authored and facebook-github-bot committed Jan 20, 2017
1 parent dd5a72f commit 61d6143
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions folly/experimental/FunctionScheduler.cpp
Expand Up @@ -445,6 +445,7 @@ void FunctionScheduler::runOneFunction(std::unique_lock<std::mutex>& lock,
}
if (currentFunction_->runOnce) {
// Don't reschedule if the function only needed to run once.
currentFunction_ = nullptr;
return;
}
// Clear currentFunction_
Expand Down
7 changes: 7 additions & 0 deletions folly/experimental/test/FunctionSchedulerTest.cpp
Expand Up @@ -456,6 +456,13 @@ TEST(FunctionScheduler, AddWithRunOnce) {
EXPECT_EQ(2, total);
delay(2);
EXPECT_EQ(2, total);

fs.addFunctionOnce([&] { total += 2; }, "add2");
delay(1);
EXPECT_EQ(4, total);
delay(2);
EXPECT_EQ(4, total);

fs.shutdown();
}

Expand Down

0 comments on commit 61d6143

Please sign in to comment.