Bug 1293212 - Add MOZ_MUST_USE to prevent potential bugs. r=smaug
authorWei-Cheng Pan <wpan@mozilla.com>
Mon, 08 Aug 2016 18:16:15 +0800
changeset 311510 18c67e7044be236416c0cd560a062a080fdb0189
parent 311509 618ef1b4953f77054cac10c6924df88d356e7d53
child 311511 605ef7faa292854edff8f40121aa7f8a5e4bea00
push id31781
push userwpan@mozilla.com
push dateMon, 29 Aug 2016 03:13:36 +0000
treeherderautoland@18c67e7044be [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1293212
milestone51.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 1293212 - Add MOZ_MUST_USE to prevent potential bugs. r=smaug MozReview-Commit-ID: EuyeBkDlk2G
docshell/base/nsDocShell.cpp
uriloader/base/nsDocLoader.cpp
uriloader/base/nsDocLoader.h
uriloader/base/nsURILoader.h
uriloader/exthandler/ContentHandlerService.h
uriloader/exthandler/ExternalHelperAppChild.h
uriloader/exthandler/android/nsMIMEInfoAndroid.h
uriloader/exthandler/android/nsOSHelperAppService.h
uriloader/exthandler/gonk/nsOSHelperAppService.h
uriloader/exthandler/mac/nsDecodeAppleFile.h
uriloader/exthandler/mac/nsMIMEInfoMac.h
uriloader/exthandler/mac/nsOSHelperAppService.h
uriloader/exthandler/mac/nsOSHelperAppService.mm
uriloader/exthandler/nsExternalHelperAppService.h
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -3311,17 +3311,18 @@ nsDocShell::RecomputeCanExecuteScripts()
   }
 }
 
 nsresult
 nsDocShell::SetDocLoaderParent(nsDocLoader* aParent)
 {
   bool wasFrame = IsFrame();
 
-  nsDocLoader::SetDocLoaderParent(aParent);
+  nsresult rv = nsDocLoader::SetDocLoaderParent(aParent);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISupportsPriority> priorityGroup = do_QueryInterface(mLoadGroup);
   if (wasFrame != IsFrame() && priorityGroup) {
     priorityGroup->AdjustPriority(wasFrame ? -1 : 1);
   }
 
   // Curse ambiguous nsISupports inheritance!
   nsISupports* parent = GetAsSupports(aParent);
@@ -4031,17 +4032,18 @@ nsDocShell::AddChild(nsIDocShellTreeItem
       return NS_ERROR_ILLEGAL_VALUE;
     }
     ancestor = ancestor->GetParent();
   } while (ancestor);
 
   // Make sure to remove the child from its current parent.
   nsDocLoader* childsParent = childAsDocLoader->GetParent();
   if (childsParent) {
-    childsParent->RemoveChildLoader(childAsDocLoader);
+    nsresult rv = childsParent->RemoveChildLoader(childAsDocLoader);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Make sure to clear the treeowner in case this child is a different type
   // from us.
   aChild->SetTreeOwner(nullptr);
 
   nsresult res = AddChildLoader(childAsDocLoader);
   NS_ENSURE_SUCCESS(res, res);
--- a/uriloader/base/nsDocLoader.cpp
+++ b/uriloader/base/nsDocLoader.cpp
@@ -340,17 +340,18 @@ nsDocLoader::GetLoadGroup(nsILoadGroup**
 void
 nsDocLoader::Destroy()
 {
   Stop();
 
   // Remove the document loader from the parent list of loaders...
   if (mParent)
   {
-    mParent->RemoveChildLoader(this);
+    nsresult rv = mParent->RemoveChildLoader(this);
+    NS_WARN_IF(NS_FAILED(rv));
   }
 
   // Release all the information about network requests...
   ClearRequestInfoHash();
 
   mListenerInfoList.Clear();
   mListenerInfoList.Compact();
 
@@ -371,17 +372,18 @@ nsDocLoader::DestroyChildren()
   // loader
   for (uint32_t i=0; i < count; i++)
   {
     nsIDocumentLoader* loader = ChildAt(i);
 
     if (loader) {
       // This is a safe cast, as we only put nsDocLoader objects into the
       // array
-      static_cast<nsDocLoader*>(loader)->SetDocLoaderParent(nullptr);
+      nsresult rv = static_cast<nsDocLoader*>(loader)->SetDocLoaderParent(nullptr);
+      NS_WARN_IF(NS_FAILED(rv));
     }
   }
   mChildList.Clear();
 }
 
 NS_IMETHODIMP
 nsDocLoader::OnStartRequest(nsIRequest *request, nsISupports *aCtxt)
 {
@@ -611,26 +613,26 @@ nsDocLoader::OnStopRequest(nsIRequest *a
   return NS_OK;
 }
 
 
 nsresult nsDocLoader::RemoveChildLoader(nsDocLoader* aChild)
 {
   nsresult rv = mChildList.RemoveElement(aChild) ? NS_OK : NS_ERROR_FAILURE;
   if (NS_SUCCEEDED(rv)) {
-    aChild->SetDocLoaderParent(nullptr);
+    rv = aChild->SetDocLoaderParent(nullptr);
   }
   return rv;
 }
 
 nsresult nsDocLoader::AddChildLoader(nsDocLoader* aChild)
 {
   nsresult rv = mChildList.AppendElement(aChild) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
   if (NS_SUCCEEDED(rv)) {
-    aChild->SetDocLoaderParent(this);
+    rv = aChild->SetDocLoaderParent(this);
   }
   return rv;
 }
 
 NS_IMETHODIMP nsDocLoader::GetDocumentChannel(nsIChannel ** aChannel)
 {
   if (!mDocumentRequest) {
     *aChannel = nullptr;
--- a/uriloader/base/nsDocLoader.h
+++ b/uriloader/base/nsDocLoader.h
@@ -53,26 +53,26 @@ class nsDocLoader : public nsIDocumentLo
                     public nsISecurityEventSink,
                     public nsISupportsPriority
 {
 public:
     NS_DECLARE_STATIC_IID_ACCESSOR(NS_THIS_DOCLOADER_IMPL_CID)
 
     nsDocLoader();
 
-    virtual nsresult Init();
+    virtual MOZ_MUST_USE nsresult Init();
 
     static already_AddRefed<nsDocLoader> GetAsDocLoader(nsISupports* aSupports);
     // Needed to deal with ambiguous inheritance from nsISupports...
     static nsISupports* GetAsSupports(nsDocLoader* aDocLoader) {
         return static_cast<nsIDocumentLoader*>(aDocLoader);
     }
 
     // Add aDocLoader as a child to the docloader service.
-    static nsresult AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader);
+    static MOZ_MUST_USE nsresult AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader);
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIDOCUMENTLOADER
 
     // nsIProgressEventSink
     NS_DECL_NSIPROGRESSEVENTSINK
 
     NS_DECL_NSISECURITYEVENTSINK
@@ -84,20 +84,20 @@ public:
     NS_DECL_NSIINTERFACEREQUESTOR
     NS_DECL_NSICHANNELEVENTSINK
     NS_DECL_NSISUPPORTSPRIORITY
 
     // Implementation specific methods...
 
     // Remove aChild from our childlist.  This nulls out the child's mParent
     // pointer.
-    nsresult RemoveChildLoader(nsDocLoader *aChild);
+    MOZ_MUST_USE nsresult RemoveChildLoader(nsDocLoader *aChild);
     // Add aChild to our child list.  This will set aChild's mParent pointer to
     // |this|.
-    nsresult AddChildLoader(nsDocLoader* aChild);
+    MOZ_MUST_USE nsresult AddChildLoader(nsDocLoader* aChild);
     nsDocLoader* GetParent() const { return mParent; }
 
     struct nsListenerInfo {
       nsListenerInfo(nsIWeakReference *aListener, unsigned long aNotifyMask)
         : mWeakListener(aListener),
           mNotifyMask(aNotifyMask)
       {
       }
@@ -107,17 +107,17 @@ public:
 
       // Mask indicating which notifications the listener wants to receive.
       unsigned long mNotifyMask;
     };
 
 protected:
     virtual ~nsDocLoader();
 
-    virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
+    virtual MOZ_MUST_USE nsresult SetDocLoaderParent(nsDocLoader * aLoader);
 
     bool IsBusy();
 
     void Destroy();
     virtual void DestroyChildren();
 
     nsIDocumentLoader* ChildAt(int32_t i) {
         return mChildList.SafeElementAt(i, nullptr);
@@ -159,17 +159,17 @@ protected:
                             nsresult aStatus,
                             const char16_t* aMessage);
 
     void FireOnLocationChange(nsIWebProgress* aWebProgress,
                               nsIRequest* aRequest,
                               nsIURI *aUri,
                               uint32_t aFlags);
 
-    bool RefreshAttempted(nsIWebProgress* aWebProgress,
+    MOZ_MUST_USE bool RefreshAttempted(nsIWebProgress* aWebProgress,
                             nsIURI *aURI,
                             int32_t aDelay,
                             bool aSameURI);
 
     // this function is overridden by the docshell, it is provided so that we
     // can pass more information about redirect state (the normal OnStateChange
     // doesn't get the new channel).
     // @param aRedirectFlags The flags being sent to OnStateChange that
@@ -182,17 +182,17 @@ protected:
 
     void doStartDocumentLoad();
     void doStartURLLoad(nsIRequest *request);
     void doStopURLLoad(nsIRequest *request, nsresult aStatus);
     void doStopDocumentLoad(nsIRequest *request, nsresult aStatus);
 
     // Inform a parent docloader that aChild is about to call its onload
     // handler.
-    bool ChildEnteringOnload(nsIDocumentLoader* aChild) {
+    MOZ_MUST_USE bool ChildEnteringOnload(nsIDocumentLoader* aChild) {
         // It's ok if we're already in the list -- we'll just be in there twice
         // and then the RemoveObject calls from ChildDoneWithOnload will remove
         // us.
         return mChildrenInOnload.AppendObject(aChild);
     }
 
     // Inform a parent docloader that aChild is done calling its onload
     // handler.
--- a/uriloader/base/nsURILoader.h
+++ b/uriloader/base/nsURILoader.h
@@ -30,21 +30,21 @@ public:
 
 protected:
   ~nsURILoader();
 
   /**
    * Equivalent to nsIURILoader::openChannel, but allows specifying whether the
    * channel is opened already.
    */
-  nsresult OpenChannel(nsIChannel* channel,
-                                   uint32_t aFlags,
-                                   nsIInterfaceRequestor* aWindowContext,
-                                   bool aChannelOpen,
-                                   nsIStreamListener** aListener);
+  MOZ_MUST_USE nsresult OpenChannel(nsIChannel* channel,
+                                    uint32_t aFlags,
+                                    nsIInterfaceRequestor* aWindowContext,
+                                    bool aChannelOpen,
+                                    nsIStreamListener** aListener);
 
   /**
    * we shouldn't need to have an owning ref count on registered
    * content listeners because they are supposed to unregister themselves
    * when they go away. This array stores weak references
    */
   nsCOMArray<nsIWeakReference> m_listeners;
 
--- a/uriloader/exthandler/ContentHandlerService.h
+++ b/uriloader/exthandler/ContentHandlerService.h
@@ -16,17 +16,17 @@ class PHandlerServiceChild;
 
 class ContentHandlerService : public nsIHandlerService
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIHANDLERSERVICE
 
   ContentHandlerService();
-  nsresult Init();
+  MOZ_MUST_USE nsresult Init();
   static void nsIHandlerInfoToHandlerInfo(nsIHandlerInfo* aInfo, HandlerInfo* aHandlerInfo);
 
 private:
   virtual ~ContentHandlerService();
   RefPtr<HandlerServiceChild> mHandlerServiceChild;
   nsClassHashtable<nsCStringHashKey, nsCString> mExtToTypeMap;
 };
 
--- a/uriloader/exthandler/ExternalHelperAppChild.h
+++ b/uriloader/exthandler/ExternalHelperAppChild.h
@@ -28,17 +28,17 @@ public:
 
     // Give the listener a real nsExternalAppHandler to complete processing on
     // the child.
     void SetHandler(nsExternalAppHandler *handler) { mHandler = handler; }
 
     virtual bool RecvCancel(const nsresult& aStatus) override;
 private:
     virtual ~ExternalHelperAppChild();
-    nsresult DivertToParent(nsIDivertableChannel *divertable, nsIRequest *request);
+    MOZ_MUST_USE nsresult DivertToParent(nsIDivertableChannel *divertable, nsIRequest *request);
 
     RefPtr<nsExternalAppHandler> mHandler;
     nsresult mStatus;
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/uriloader/exthandler/android/nsMIMEInfoAndroid.h
+++ b/uriloader/exthandler/android/nsMIMEInfoAndroid.h
@@ -8,38 +8,38 @@
 
 #include "nsMIMEInfoImpl.h"
 #include "nsIMutableArray.h"
 #include "nsAndroidHandlerApp.h"
 
 class nsMIMEInfoAndroid final : public nsIMIMEInfo
 {
 public:
-  static bool
+  static MOZ_MUST_USE bool
   GetMimeInfoForMimeType(const nsACString& aMimeType, 
                          nsMIMEInfoAndroid** aMimeInfo);
-  static bool
+  static MOZ_MUST_USE bool
   GetMimeInfoForFileExt(const nsACString& aFileExt, 
                         nsMIMEInfoAndroid** aMimeInfo);
 
-  static nsresult 
+  static MOZ_MUST_USE nsresult
   GetMimeInfoForURL(const nsACString &aURL, bool *found,
                     nsIHandlerInfo **info);
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIMIMEINFO
   NS_DECL_NSIHANDLERINFO
 
   nsMIMEInfoAndroid(const nsACString& aMIMEType);
 
 private:
   ~nsMIMEInfoAndroid() {}
 
-  virtual nsresult LaunchDefaultWithFile(nsIFile* aFile);
-  virtual nsresult LoadUriInternal(nsIURI *aURI);
+  virtual MOZ_MUST_USE nsresult LaunchDefaultWithFile(nsIFile* aFile);
+  virtual MOZ_MUST_USE nsresult LoadUriInternal(nsIURI *aURI);
   nsCOMPtr<nsIMutableArray> mHandlerApps;
   nsCString mType;
   nsTArray<nsCString> mExtensions;
   bool mAlwaysAsk;
   nsHandlerInfoAction mPrefAction;
   nsString mDescription;
   nsCOMPtr<nsIHandlerApp> mPrefApp;
 
--- a/uriloader/exthandler/android/nsOSHelperAppService.h
+++ b/uriloader/exthandler/android/nsOSHelperAppService.h
@@ -15,17 +15,17 @@ public:
     nsOSHelperAppService();
     virtual ~nsOSHelperAppService();
 
     virtual already_AddRefed<nsIMIMEInfo>
     GetMIMEInfoFromOS(const nsACString& aMIMEType,
                       const nsACString& aFileExt,
                       bool* aFound);
 
-    virtual nsresult
+    virtual MOZ_MUST_USE nsresult
     OSProtocolHandlerExists(const char* aScheme,
                             bool* aExists);
 
     NS_IMETHOD GetProtocolHandlerInfoFromOS(const nsACString &aScheme,
                                             bool *found,
                                             nsIHandlerInfo **_retval);
 
     static nsIHandlerApp*
--- a/uriloader/exthandler/gonk/nsOSHelperAppService.h
+++ b/uriloader/exthandler/gonk/nsOSHelperAppService.h
@@ -26,14 +26,14 @@ public:
     nsOSHelperAppService();
     virtual ~nsOSHelperAppService();
 
     virtual already_AddRefed<nsIMIMEInfo>
     GetMIMEInfoFromOS(const nsACString& aMIMEType,
                       const nsACString& aFileExt,
                       bool* aFound);
 
-    virtual nsresult
+    virtual MOZ_MUST_USE nsresult
     OSProtocolHandlerExists(const char* aScheme,
                             bool* aExists);
 };
 
 #endif /* nsOSHelperAppService_h */
--- a/uriloader/exthandler/mac/nsDecodeAppleFile.h
+++ b/uriloader/exthandler/mac/nsDecodeAppleFile.h
@@ -78,17 +78,17 @@ class nsDecodeAppleFile : public nsIOutp
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIOUTPUTSTREAM
   
   nsDecodeAppleFile();
   virtual ~nsDecodeAppleFile();
   
-  nsresult Initialize(nsIOutputStream *output, nsIFile *file);
+  MOZ_MUST_USE nsresult Initialize(nsIOutputStream *output, nsIFile *file);
   
 private:
   #define MAX_BUFFERSIZE    1024
   enum ParserState {parseHeaders, parseEntries, parseLookupPart, parsePart, parseSkipPart,
                     parseDataFork, parseResourceFork, parseWriteThrough};
   
   nsCOMPtr<nsIOutputStream> m_output;
   FSSpec            m_fsFileSpec;
--- a/uriloader/exthandler/mac/nsMIMEInfoMac.h
+++ b/uriloader/exthandler/mac/nsMIMEInfoMac.h
@@ -11,24 +11,24 @@ class nsMIMEInfoMac : public nsMIMEInfoI
   public:
     explicit nsMIMEInfoMac(const char* aMIMEType = "") : nsMIMEInfoImpl(aMIMEType) {}
     explicit nsMIMEInfoMac(const nsACString& aMIMEType) : nsMIMEInfoImpl(aMIMEType) {}
     nsMIMEInfoMac(const nsACString& aType, HandlerClass aClass) :
       nsMIMEInfoImpl(aType, aClass) {}
 
     NS_IMETHOD LaunchWithFile(nsIFile* aFile);
   protected:
-    virtual nsresult LoadUriInternal(nsIURI *aURI);
+    virtual MOZ_MUST_USE nsresult LoadUriInternal(nsIURI *aURI);
 #ifdef DEBUG
-    virtual nsresult LaunchDefaultWithFile(nsIFile* aFile) {
+    virtual MOZ_MUST_USE nsresult LaunchDefaultWithFile(nsIFile* aFile) {
       NS_NOTREACHED("do not call this method, use LaunchWithFile");
       return NS_ERROR_UNEXPECTED;
     }
 #endif
-    static nsresult OpenApplicationWithURI(nsIFile *aApplication, 
-                                                       const nsCString& aURI);
+    static MOZ_MUST_USE nsresult OpenApplicationWithURI(nsIFile *aApplication,
+                                                        const nsCString& aURI);
                                                        
     NS_IMETHOD GetDefaultDescription(nsAString& aDefaultDescription);
     
 };
 
 
 #endif
--- a/uriloader/exthandler/mac/nsOSHelperAppService.h
+++ b/uriloader/exthandler/mac/nsOSHelperAppService.h
@@ -31,18 +31,18 @@ public:
   NS_IMETHOD GetProtocolHandlerInfoFromOS(const nsACString &aScheme,
                                           bool *found,
                                           nsIHandlerInfo **_retval);
 
   // GetFileTokenForPath must be implemented by each platform. 
   // platformAppPath --> a platform specific path to an application that we got out of the 
   //                     rdf data source. This can be a mac file spec, a unix path or a windows path depending on the platform
   // aFile --> an nsIFile representation of that platform application path.
-  virtual nsresult GetFileTokenForPath(const char16_t * platformAppPath, nsIFile ** aFile);
+  virtual MOZ_MUST_USE nsresult GetFileTokenForPath(const char16_t * platformAppPath, nsIFile ** aFile);
 
-  nsresult OSProtocolHandlerExists(const char * aScheme,
-                                   bool * aHandlerExists);
+  MOZ_MUST_USE nsresult OSProtocolHandlerExists(const char * aScheme,
+                                                bool * aHandlerExists);
 
 private:
   uint32_t mPermissions;
 };
 
 #endif // nsOSHelperAppService_h__
--- a/uriloader/exthandler/mac/nsOSHelperAppService.mm
+++ b/uriloader/exthandler/mac/nsOSHelperAppService.mm
@@ -555,14 +555,15 @@ nsOSHelperAppService::GetProtocolHandler
 
   if (!*found) {
     // Code that calls this requires an object regardless if the OS has
     // something for us, so we return the empty object.
     return NS_OK;
   }
 
   nsAutoString desc;
-  GetApplicationDescription(aScheme, desc);
+  rv = GetApplicationDescription(aScheme, desc);
+  NS_WARN_IF(NS_FAILED(rv));
   handlerInfo->SetDefaultDescription(desc);
 
   return NS_OK;
 }
 
--- a/uriloader/exthandler/nsExternalHelperAppService.h
+++ b/uriloader/exthandler/nsExternalHelperAppService.h
@@ -62,17 +62,17 @@ public:
   NS_DECL_NSIOBSERVER
 
   nsExternalHelperAppService();
 
   /**
    * Initializes internal state. Will be called automatically when
    * this service is first instantiated.
    */
-  nsresult Init();
+  MOZ_MUST_USE nsresult Init();
  
   /**
    * Given a mimetype and an extension, looks up a mime info from the OS.
    * The mime type is given preference. This function follows the same rules
    * as nsIMIMEService::GetFromTypeAndExtension.
    * This is supposed to be overridden by the platform-specific
    * nsOSHelperAppService!
    * @param aFileExt The file extension; may be empty. UTF-8 encoded.