From 4ffd39d6962255cf227b7dbda2f76a54759069ac Mon Sep 17 00:00:00 2001 From: Andrii Grynenko Date: Tue, 17 May 2016 17:21:56 -0700 Subject: [PATCH] Fix one more race in Promise::setTry Summary: Baton::post has to be the last step of Promise::setTry. If Promise is not owned by the posting thread, it may be destroyed right after Baton::post is called. Reviewed By: pavlo-fb Differential Revision: D3312506 fbshipit-source-id: 6d5c3f0925c3bb9cd3f981e7550f888d5ed76189 --- folly/experimental/fibers/Promise-inl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/folly/experimental/fibers/Promise-inl.h b/folly/experimental/fibers/Promise-inl.h index 108a2ac4..67459855 100644 --- a/folly/experimental/fibers/Promise-inl.h +++ b/folly/experimental/fibers/Promise-inl.h @@ -63,9 +63,9 @@ void Promise::setTry(folly::Try&& t) { *value_ = std::move(t); value_ = nullptr; + // Baton::post has to be the last step here, since if Promise is not owned by + // the posting thread, it may be destroyed right after Baton::post is called. baton_->post(); - - baton_ = nullptr; } template -- 2.34.1