Commit d3233089 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Let KeepAlive::copy() allow dummy executors to expire

Summary: [Folly] Let `KeepAlive::copy()` allow dummy executors to expire, and not attempt to dereference them to perform an acquire - which, as is known in advance, would fail and return false were the executor still to be alive.

Reviewed By: andrewcox

Differential Revision: D15683240

fbshipit-source-id: e2026493af6936b8f0f1b8fe3c1cb97d2bf0f96e
parent 8d2d67e3
......@@ -146,7 +146,9 @@ class Executor {
}
KeepAlive copy() const {
return getKeepAliveToken(get());
return isKeepAliveDummy(*this) //
? makeKeepAliveDummy(get())
: getKeepAliveToken(get());
}
KeepAlive get_alias() const {
......
......@@ -215,4 +215,23 @@ TEST(ExecutorTest, GetKeepAliveTokenFromToken) {
EXPECT_EQ(0, exec.refCount);
}
TEST(ExecutorTest, CopyExpired) {
struct Ex : Executor {
void add(Func) override {}
};
Ex* ptr = nullptr;
Executor::KeepAlive<Ex> ka;
{
auto ex = std::make_unique<Ex>();
ptr = ex.get();
ka = getKeepAliveToken(ptr);
}
ka = ka.copy(); // if copy() doesn't check dummy, expect segfault
EXPECT_EQ(ptr, ka.get());
}
} // namespace folly
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