folly/futures: fix early release of non-embedded callbacks
[folly.git] / folly / futures / detail / Core.h
index b0bb2ff778ddea99ee09139ae9a36426688971dc..7516885264c2c68deff2e6dd17fb74f6cb9315c1 100644 (file)
@@ -216,7 +216,7 @@ class Core {
     // detachPromise() and setResult() should never be called in parallel
     // so we don't need to protect this.
     if (UNLIKELY(!result_)) {
-      setResult(Try<T>(exception_wrapper(BrokenPromise())));
+      setResult(Try<T>(exception_wrapper(BrokenPromise(typeid(T).name()))));
     }
     detachOne();
   }
@@ -335,12 +335,14 @@ class Core {
           x->add([this]() mutable {
             SCOPE_EXIT { detachOne(); };
             RequestContext::setContext(context_);
+            SCOPE_EXIT { callback_ = {}; };
             callback_(std::move(*result_));
           });
         } else {
           x->addWithPriority([this]() mutable {
             SCOPE_EXIT { detachOne(); };
             RequestContext::setContext(context_);
+            SCOPE_EXIT { callback_ = {}; };
             callback_(std::move(*result_));
           }, priority);
         }
@@ -348,10 +350,12 @@ class Core {
         --attached_; // Account for extra ++attached_ before try
         RequestContext::setContext(context_);
         result_ = Try<T>(exception_wrapper(std::current_exception()));
+        SCOPE_EXIT { callback_ = {}; };
         callback_(std::move(*result_));
       }
     } else {
       RequestContext::setContext(context_);
+      SCOPE_EXIT { callback_ = {}; };
       callback_(std::move(*result_));
     }
   }
@@ -437,14 +441,14 @@ struct CollectVariadicContext {
                   std::move(*std::get<sizeof...(ts2)>(o)));
   }
 
-  static std::tuple<Ts...> unwrap(std::tuple<folly::Try<Ts>...>&& o,
+  static std::tuple<Ts...> unwrap(std::tuple<folly::Try<Ts>...>&& /* o */,
                                   Ts&&... ts) {
     return std::tuple<Ts...>(std::forward<Ts>(ts)...);
   }
 };
 
-template <template <typename ...> class T, typename... Ts>
-void collectVariadicHelper(const std::shared_ptr<T<Ts...>>& ctx) {
+template <template <typename...> class T, typename... Ts>
+void collectVariadicHelper(const std::shared_ptr<T<Ts...>>& /* ctx */) {
   // base case
 }