Bug 1454052 - make MakeScopeExit a MOZ_MUST_USE function; r=gerald
authorNathan Froyd <froydnj@mozilla.com>
Wed, 18 Apr 2018 12:14:18 -0400
changeset 414242 b49bd215b26e8831015572770ff8ec7dc91e4dad
parent 414241 9d00dc13a5639d89a58c27fe85499d6706b14b18
child 414243 a12624f2ce5b9d32c0a68ed8ed1ac54f99cffdd2
push id102296
push usernfroyd@mozilla.com
push dateWed, 18 Apr 2018 16:14:42 +0000
treeherdermozilla-inbound@b49bd215b26e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1454052
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1454052 - make MakeScopeExit a MOZ_MUST_USE function; r=gerald Otherwise, one can do thinkos like: MakeScopeExit(...); and the scope exiting function will execute much earlier than the intended: auto guard = MakeScopeExit(...);
mfbt/ScopeExit.h
xpcom/threads/PrioritizedEventQueue.cpp
--- a/mfbt/ScopeExit.h
+++ b/mfbt/ScopeExit.h
@@ -75,16 +75,17 @@
  * behaviors:
  *
  * - if |release()| has not been called, the cleanup is always performed at
  *   the end of the scope;
  * - if |release()| has been called, nothing will happen at the end of the
  *   scope.
  */
 
+#include "mozilla/Attributes.h"
 #include "mozilla/GuardObjects.h"
 #include "mozilla/Move.h"
 
 namespace mozilla {
 
 template <typename ExitFunction>
 class MOZ_STACK_CLASS ScopeExit {
   ExitFunction mExitFunction;
@@ -119,17 +120,17 @@ public:
 
 private:
   explicit ScopeExit(const ScopeExit&) = delete;
   ScopeExit& operator=(const ScopeExit&) = delete;
   ScopeExit& operator=(ScopeExit&&) = delete;
 };
 
 template <typename ExitFunction>
-ScopeExit<ExitFunction>
+MOZ_MUST_USE ScopeExit<ExitFunction>
 MakeScopeExit(ExitFunction&& exitFunction)
 {
   return ScopeExit<ExitFunction>(mozilla::Move(exitFunction));
 }
 
 } /* namespace mozilla */
 
 #endif /* mozilla_ScopeExit_h */
--- a/xpcom/threads/PrioritizedEventQueue.cpp
+++ b/xpcom/threads/PrioritizedEventQueue.cpp
@@ -180,17 +180,17 @@ PrioritizedEventQueue<InnerQueueT>::Sele
   return queue;
 }
 
 template<class InnerQueueT>
 already_AddRefed<nsIRunnable>
 PrioritizedEventQueue<InnerQueueT>::GetEvent(EventPriority* aPriority,
                                              const MutexAutoLock& aProofOfLock)
 {
-  MakeScopeExit([&] {
+  auto guard = MakeScopeExit([&] {
     mHasPendingEventsPromisedIdleEvent = false;
   });
 
 #ifndef RELEASE_OR_BETA
   // Clear mNextIdleDeadline so that it is possible to determine that
   // we're running an idle runnable in ProcessNextEvent.
   *mNextIdleDeadline = TimeStamp();
 #endif