Destroy promise/future callback functions before waking waiters
Summary:
Code may pass a callback which captures an object with a destructor which mutates through a stored reference, triggering heap-use-after-free or stack-use-after-scope.
```lang=c++
void performDataRace() {
auto number = std::make_unique<int>(0);
auto guard = folly::makeGuard([&number] { *number = 1; });
folly::via(getSomeExecutor(), [guard = std::move(guard)]() mutable {}).wait();
// data race - we may wake and destruct number before guard is destructed on the
// executor thread, which is both stack-use-after-scope and heap-use-after-free!
}
```
We can avoid this condition by always destructing the provided functor before setting any result on the promise.
Reviewed By: spacedentist
Differential Revision:
D4982969
fbshipit-source-id:
71134c1657bdd4c38c12d8ca17f8335ef4c27352