Bug 1028588 - Fix dangerous public destructors in parser/ - r=wchen
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 27 Jun 2014 14:41:03 -0400
changeset 191305 a588fb7df4a3b881d62d56ef97b5eaed870fb4c9
parent 191304 d0a80ba46f6fdebf28c7faa188655a84446e2e37
child 191306 303027a0da95c3ce6674637ee338cd066703462f
push id27041
push userphilringnalda@gmail.com
push dateSun, 29 Jun 2014 00:39:21 +0000
treeherdermozilla-central@afa67a2f7905 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswchen
bugs1028588
milestone33.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 1028588 - Fix dangerous public destructors in parser/ - r=wchen
parser/html/nsHtml5Module.cpp
parser/html/nsHtml5Parser.h
parser/html/nsHtml5StreamListener.h
parser/html/nsHtml5StreamParser.h
parser/html/nsHtml5StringParser.h
parser/html/nsParserUtils.h
parser/htmlparser/src/CNavDTD.h
parser/htmlparser/src/nsExpatDriver.h
parser/htmlparser/src/nsHTMLTokenizer.h
parser/htmlparser/src/nsParser.h
parser/htmlparser/src/nsParserService.h
parser/xml/src/nsSAXAttributes.h
parser/xml/src/nsSAXLocator.h
parser/xml/src/nsSAXXMLReader.h
--- a/parser/html/nsHtml5Module.cpp
+++ b/parser/html/nsHtml5Module.cpp
@@ -98,16 +98,18 @@ class nsHtml5ParserThreadTerminator MOZ_
                    "Unexpected topic");
       if (mThread) {
         mThread->Shutdown();
         mThread = nullptr;
       }
       return NS_OK;
     }
   private:
+    ~nsHtml5ParserThreadTerminator() {}
+
     nsCOMPtr<nsIThread> mThread;
 };
 
 NS_IMPL_ISUPPORTS(nsHtml5ParserThreadTerminator, nsIObserver)
 
 // static 
 nsIThread*
 nsHtml5Module::GetStreamParserThread()
--- a/parser/html/nsHtml5Parser.h
+++ b/parser/html/nsHtml5Parser.h
@@ -32,17 +32,16 @@ class nsHtml5Parser : public nsIParser,
 {
   public:
     NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
     NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
     NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHtml5Parser, nsIParser)
 
     nsHtml5Parser();
-    virtual ~nsHtml5Parser();
 
     /* Start nsIParser */
     /**
      * No-op for backwards compat.
      */
     NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink);
 
     /**
@@ -261,16 +260,18 @@ class nsHtml5Parser : public nsIParser,
 
     /**
      * Parse until pending data is exhausted or a script blocks the parser
      */
     void ParseUntilBlocked();
 
   private:
 
+    virtual ~nsHtml5Parser();
+
     // State variables
 
     /**
      * Whether the last character tokenized was a carriage return (for CRLF)
      */
     bool                          mLastWasCR;
 
     /**
--- a/parser/html/nsHtml5StreamListener.h
+++ b/parser/html/nsHtml5StreamListener.h
@@ -28,27 +28,28 @@
  * threads, so there is no need to have a mutex around nsHtml5RefPtr to
  * prevent it from double-releasing nsHtml5StreamParser.
  */
 class nsHtml5StreamListener : public nsIStreamListener,
                               public nsIThreadRetargetableStreamListener
 {
 public:
   nsHtml5StreamListener(nsHtml5StreamParser* aDelegate);
-  virtual ~nsHtml5StreamListener();
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIREQUESTOBSERVER
   NS_DECL_NSISTREAMLISTENER
   NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
 
   inline nsHtml5StreamParser* GetDelegate()
   {
     return mDelegate;
   }
 
   void DropDelegate();
 
 private:
+  virtual ~nsHtml5StreamListener();
+
   nsHtml5RefPtr<nsHtml5StreamParser> mDelegate;
 };
 
 #endif // nsHtml5StreamListener_h
--- a/parser/html/nsHtml5StreamParser.h
+++ b/parser/html/nsHtml5StreamParser.h
@@ -112,18 +112,16 @@ class nsHtml5StreamParser : public nsICh
     NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHtml5StreamParser,
                                              nsICharsetDetectionObserver)
 
     static void InitializeStatics();
 
     nsHtml5StreamParser(nsHtml5TreeOpExecutor* aExecutor,
                         nsHtml5Parser* aOwner,
                         eParserMode aMode);
-                        
-    virtual ~nsHtml5StreamParser();
 
     // Methods that nsHtml5StreamListener calls
     nsresult CheckListenerChain();
 
     nsresult OnStartRequest(nsIRequest* aRequest, nsISupports* aContext);
 
     nsresult OnDataAvailable(nsIRequest* aRequest,
                              nsISupports* aContext,
@@ -204,16 +202,17 @@ class nsHtml5StreamParser : public nsICh
     /**
      * Sets the URL for View Source title in case this parser ends up being
      * used for View Source. If aURL is a view-source: URL, takes the inner
      * URL. data: URLs are shown with an ellipsis instead of the actual data.
      */
     void SetViewSourceTitle(nsIURI* aURL);
 
   private:
+    virtual ~nsHtml5StreamParser();
 
 #ifdef DEBUG
     bool IsParserThread() {
       bool ret;
       mThread->IsOnCurrentThread(&ret);
       return ret;
     }
 #endif
--- a/parser/html/nsHtml5StringParser.h
+++ b/parser/html/nsHtml5StringParser.h
@@ -20,17 +20,16 @@ class nsHtml5StringParser : public nsPar
 
     NS_DECL_ISUPPORTS
 
     /**
      * Constructor for use ONLY by nsContentUtils. Others, please call the
      * nsContentUtils statics that wrap this.
      */
     nsHtml5StringParser();
-    virtual ~nsHtml5StringParser();
 
     /**
      * Invoke the fragment parsing algorithm (innerHTML).
      * DO NOT CALL from outside nsContentUtils.cpp.
      *
      * @param aSourceBuffer the string being set as innerHTML
      * @param aTargetNode the target container
      * @param aContextLocalName local name of context node
@@ -53,16 +52,18 @@ class nsHtml5StringParser : public nsPar
      *
      */
     nsresult ParseDocument(const nsAString& aSourceBuffer,
                            nsIDocument* aTargetDoc,
                            bool aScriptingEnabledForNoscriptParsing);
 
   private:
 
+    virtual ~nsHtml5StringParser();
+
     nsresult Tokenize(const nsAString& aSourceBuffer,
                       nsIDocument* aDocument,
                       bool aScriptingEnabledForNoscriptParsing);
 
     /**
      * The tree operation executor
      */
     nsRefPtr<nsHtml5OplessBuilder>      mBuilder;
--- a/parser/html/nsParserUtils.h
+++ b/parser/html/nsParserUtils.h
@@ -8,15 +8,16 @@
 
 #include "nsIScriptableUnescapeHTML.h"
 #include "nsIParserUtils.h"
 #include "mozilla/Attributes.h"
 
 class nsParserUtils MOZ_FINAL : public nsIScriptableUnescapeHTML,
                                 public nsIParserUtils
 {
+  ~nsParserUtils() {}
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSISCRIPTABLEUNESCAPEHTML
   NS_DECL_NSIPARSERUTILS
 };
 
 #endif // nsParserUtils_h
--- a/parser/htmlparser/src/CNavDTD.h
+++ b/parser/htmlparser/src/CNavDTD.h
@@ -19,19 +19,20 @@ class nsIHTMLContentSink;
 #endif
 
 class CNavDTD : public nsIDTD
 {
 #ifdef _MSC_VER
 #pragma warning( default : 4275 )
 #endif
 
+    virtual ~CNavDTD();
+
 public:
     CNavDTD();
-    virtual ~CNavDTD();
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIDTD
 };
 
 #endif
 
 
--- a/parser/htmlparser/src/nsExpatDriver.h
+++ b/parser/htmlparser/src/nsExpatDriver.h
@@ -18,24 +18,25 @@
 
 class nsIExpatSink;
 class nsIExtendedExpatSink;
 struct nsCatalogData;
 
 class nsExpatDriver : public nsIDTD,
                       public nsITokenizer
 {
+  virtual ~nsExpatDriver();
+
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSIDTD
   NS_DECL_NSITOKENIZER
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsExpatDriver, nsIDTD)
 
   nsExpatDriver();
-  virtual ~nsExpatDriver();
 
   int HandleExternalEntityRef(const char16_t *aOpenEntityNames,
                               const char16_t *aBase,
                               const char16_t *aSystemId,
                               const char16_t *aPublicId);
   nsresult HandleStartElement(const char16_t *aName, const char16_t **aAtts);
   nsresult HandleEndElement(const char16_t *aName);
   nsresult HandleCharacterData(const char16_t *aCData, const uint32_t aLength);
--- a/parser/htmlparser/src/nsHTMLTokenizer.h
+++ b/parser/htmlparser/src/nsHTMLTokenizer.h
@@ -17,18 +17,19 @@
 #include "nsISupports.h"
 #include "nsITokenizer.h"
 
 #ifdef _MSC_VER
 #pragma warning( disable : 4275 )
 #endif
 
 class nsHTMLTokenizer MOZ_FINAL : public nsITokenizer {
+  ~nsHTMLTokenizer() {}
+
 public:
-  
   NS_DECL_ISUPPORTS
   NS_DECL_NSITOKENIZER
   nsHTMLTokenizer();
 };
 
 #endif
 
 
--- a/parser/htmlparser/src/nsParser.h
+++ b/parser/htmlparser/src/nsParser.h
@@ -61,16 +61,22 @@ class nsIRunnable;
 #pragma warning( disable : 4275 )
 #endif
 
 
 class nsParser : public nsIParser,
                  public nsIStreamListener,
                  public nsSupportsWeakReference
 {
+    /**
+     * Destructor
+     * @update  gess5/11/98
+     */
+    virtual ~nsParser();
+
   public:
     /**
      * Called on module init
      */
     static nsresult Init();
 
     /**
      * Called on module shutdown
@@ -82,22 +88,16 @@ class nsParser : public nsIParser,
 
     /**
      * default constructor
      * @update	gess5/11/98
      */
     nsParser();
 
     /**
-     * Destructor
-     * @update	gess5/11/98
-     */
-    virtual ~nsParser();
-
-    /**
      * Select given content sink into parser for parser output
      * @update	gess5/11/98
      * @param   aSink is the new sink to be used by parser
      * @return  old sink, or nullptr
      */
     NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink);
 
     /**
--- a/parser/htmlparser/src/nsParserService.h
+++ b/parser/htmlparser/src/nsParserService.h
@@ -9,19 +9,20 @@
 #include "nsIParserService.h"
 
 extern "C" int MOZ_XMLIsLetter(const char* ptr);
 extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
 extern "C" int MOZ_XMLTranslateEntity(const char* ptr, const char* end,
                                       const char** next, char16_t* result);
 
 class nsParserService : public nsIParserService {
+  virtual ~nsParserService();
+
 public:
   nsParserService();
-  virtual ~nsParserService();
 
   NS_DECL_ISUPPORTS
 
   int32_t HTMLAtomTagToId(nsIAtom* aAtom) const;
 
   int32_t HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom) const;
 
   int32_t HTMLStringTagToId(const nsAString& aTag) const;
--- a/parser/xml/src/nsSAXAttributes.h
+++ b/parser/xml/src/nsSAXAttributes.h
@@ -31,12 +31,13 @@ struct SAXAttr
 class nsSAXAttributes MOZ_FINAL : public nsISAXMutableAttributes
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSISAXATTRIBUTES
   NS_DECL_NSISAXMUTABLEATTRIBUTES
 
 private:
+  ~nsSAXAttributes() {}
   nsTArray<SAXAttr> mAttrs;
 };
 
 #endif // nsSAXAttributes_h__
--- a/parser/xml/src/nsSAXLocator.h
+++ b/parser/xml/src/nsSAXLocator.h
@@ -23,15 +23,17 @@ public:
   NS_DECL_NSISAXLOCATOR
 
   nsSAXLocator(nsString& aPublicId,
                nsString& aSystemId,
                int32_t aLineNumber,
                int32_t aColumnNumber);
 
 private:
+  ~nsSAXLocator() {}
+
   nsString mPublicId;
   nsString mSystemId;
   int32_t mLineNumber;
   int32_t mColumnNumber;
 };
 
 #endif //nsSAXLocator_h__
--- a/parser/xml/src/nsSAXXMLReader.h
+++ b/parser/xml/src/nsSAXXMLReader.h
@@ -70,16 +70,18 @@ public:
   }
   
   virtual nsISupports *GetTarget()
   {
     return nullptr;
   }
 
 private:
+  ~nsSAXXMLReader() {}
+
   nsCOMPtr<nsISAXContentHandler> mContentHandler;
   nsCOMPtr<nsISAXDTDHandler> mDTDHandler;
   nsCOMPtr<nsISAXErrorHandler> mErrorHandler;
   nsCOMPtr<nsISAXLexicalHandler> mLexicalHandler;
   nsCOMPtr<nsIMozSAXXMLDeclarationHandler> mDeclarationHandler;
   nsCOMPtr<nsIURI> mBaseURI;
   nsCOMPtr<nsIStreamListener> mListener;
   nsCOMPtr<nsIRequestObserver> mParserObserver;