folly/futures: keep Core alive until callback has returned
authorSven Over <over@fb.com>
Wed, 24 Feb 2016 07:46:14 +0000 (23:46 -0800)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Wed, 24 Feb 2016 08:20:28 +0000 (00:20 -0800)
commit914e877b032b402e31990f80dfef1bf489daf311
treedd6ec656fd0fcad8e3a34eae2f627105068aedcc
parent9dd084035d147c2918c3526e03502252038587a5
folly/futures: keep Core alive until callback has returned

Summary:Callbacks passed to e.g. folly::Future::then (or
folly::Future::ensure) may delete the promise that keeps the
Core of the same future alive. The Core must protect itself from
destruction during callback execution.

This commit also adds a unit test to check for correct behaviour
in the "self destruction" scenario. The test should usually pass
even without the fix in Core.h. However, when you run the test
in Valgrind or ASAN, it will report problems unless the fix in
Core.h is applied.

Reviewed By: mhx

Differential Revision: D2938094

fb-gh-sync-id: 22796e168e1876ef2e3c7d7619da020be6a22073
shipit-source-id: 22796e168e1876ef2e3c7d7619da020be6a22073
folly/futures/detail/Core.h
folly/futures/test/SelfDestructTest.cpp [new file with mode: 0644]
folly/test/Makefile.am