Bug 1003297 - part 1 - don't try to return XPCOM services from mozilla::services getters post-XPCOM shutdown; r=bsmedberg
authorNathan Froyd <froydnj@mozilla.com>
Tue, 29 Apr 2014 11:51:14 -0400
changeset 181510 1f6e71553333ef44c221f054d0c0423a73a81b41
parent 181509 ab6426d96c6d4ba4d4d1d16a5eaaa454ac30435a
child 181511 060bea047502e0ea7e46ca7edd48217d381b13f0
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbsmedberg
bugs1003297
milestone32.0a1
Bug 1003297 - part 1 - don't try to return XPCOM services from mozilla::services getters post-XPCOM shutdown; r=bsmedberg
xpcom/build/Services.cpp
--- a/xpcom/build/Services.cpp
+++ b/xpcom/build/Services.cpp
@@ -1,13 +1,14 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/Likely.h"
 #include "mozilla/Services.h"
 #include "nsComponentManager.h"
 #include "nsIIOService.h"
 #include "nsIDirectoryService.h"
 #ifdef ACCESSIBILITY
 #include "nsIAccessibilityService.h"
 #endif
 #include "nsIChromeRegistry.h"
@@ -30,16 +31,19 @@ using namespace mozilla::services;
  * eg. gIOService and GetIOService()
  */
 #define MOZ_SERVICE(NAME, TYPE, CONTRACT_ID)                            \
   static TYPE* g##NAME = nullptr;                                       \
                                                                         \
   already_AddRefed<TYPE>                                                \
   mozilla::services::Get##NAME()                                        \
   {                                                                     \
+    if (MOZ_UNLIKELY(gXPCOMShuttingDown)) {                             \
+      return nullptr;                                                   \
+    }                                                                   \
     if (!g##NAME) {                                                     \
       nsCOMPtr<TYPE> os = do_GetService(CONTRACT_ID);                   \
       g##NAME = os.forget().take();                            \
     }                                                                   \
     nsRefPtr<TYPE> ret = g##NAME;                                       \
     return ret.forget();                                                \
   }                                                                     \
   NS_EXPORT_(already_AddRefed<TYPE>)                                    \