From: Michael Lee Date: Tue, 26 Sep 2017 15:35:09 +0000 (-0700) Subject: Delete conversion from Objective-C block to folly::Function X-Git-Tag: v2017.10.02.00~6 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b68452582ffa61421534d7f61f4d5f06e077ed39;p=folly.git Delete conversion from Objective-C block to folly::Function Summary: Objective-C blocks are stack allocated, and unless there is a proper assignment it isn't retained and the memory is freed. Because folly::Function used to move, it would hold a reference, but after switch to a constructor by-value, it no longer does this and we see a use-after-free. Reviewed By: yfeldblum, ericniebler Differential Revision: D5888606 fbshipit-source-id: fe4cabb2f2ae289cce0e7429e0af3935ba314720 --- diff --git a/folly/Function.h b/folly/Function.h index 55d7024c..a73a8b7a 100644 --- a/folly/Function.h +++ b/folly/Function.h @@ -491,6 +491,12 @@ class Function final : private detail::function::FunctionTraits { // not copyable Function(const Function&) = delete; +#if __OBJC__ + // Delete conversion from Objective-C blocks + template + Function(ReturnType (^)(Args...)) = delete; +#endif + /** * Move constructor */ @@ -570,6 +576,12 @@ class Function final : private detail::function::FunctionTraits { Function& operator=(const Function&) = delete; +#if __OBJC__ + // Delete conversion from Objective-C blocks + template + Function& operator=(ReturnType (^)(Args...)) = delete; +#endif + /** * Move assignment operator *