Bug 1003297 - part 2 - tidy up refcount management in mozilla::services::Get*; r=bsmedberg
authorNathan Froyd <froydnj@mozilla.com>
Tue, 29 Apr 2014 11:59:45 -0400
changeset 181511 060bea047502e0ea7e46ca7edd48217d381b13f0
parent 181510 1f6e71553333ef44c221f054d0c0423a73a81b41
child 181512 a1546ce38ecd0883a13f8cfd4e837253acbbd10b
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbsmedberg
bugs1003297
milestone32.0a1
Bug 1003297 - part 2 - tidy up refcount management in mozilla::services::Get*; r=bsmedberg
xpcom/build/Services.cpp
--- a/xpcom/build/Services.cpp
+++ b/xpcom/build/Services.cpp
@@ -36,19 +36,19 @@ using namespace mozilla::services;
   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();                            \
+      os.swap(g##NAME);                                                 \
     }                                                                   \
-    nsRefPtr<TYPE> ret = g##NAME;                                       \
+    nsCOMPtr<TYPE> ret = g##NAME;                                       \
     return ret.forget();                                                \
   }                                                                     \
   NS_EXPORT_(already_AddRefed<TYPE>)                                    \
   mozilla::services::_external_Get##NAME()                              \
   {                                                                     \
     return Get##NAME();                                                 \
   }