Bug 603844: Annotate some xlst classes with leak logging. r=sicking sr=dbaron
authorKyle Huey <khuey@kylehuey.com>
Thu, 02 Dec 2010 11:15:48 -0500
changeset 58491 feb478675a92f9d46beaeda01795f78440a7a1eb
parent 58490 40b718853f48f2b12802e6266004bc1ea35d28dd
child 58492 0988aaa45cc616f781f45fd6237d8ed91dd2abf2
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewerssicking, dbaron
bugs603844
milestone2.0b8pre
Bug 603844: Annotate some xlst classes with leak logging. r=sicking sr=dbaron
content/xslt/src/xslt/txBufferingHandler.cpp
content/xslt/src/xslt/txBufferingHandler.h
content/xslt/src/xslt/txExecutionState.cpp
content/xslt/src/xslt/txMozillaTextOutput.cpp
content/xslt/src/xslt/txMozillaTextOutput.h
content/xslt/src/xslt/txMozillaXMLOutput.cpp
content/xslt/src/xslt/txMozillaXMLOutput.h
content/xslt/src/xslt/txUnknownHandler.cpp
content/xslt/src/xslt/txUnknownHandler.h
xpcom/glue/nsTraceRefcnt.h
--- a/content/xslt/src/xslt/txBufferingHandler.cpp
+++ b/content/xslt/src/xslt/txBufferingHandler.cpp
@@ -53,69 +53,91 @@ public:
         ePITransaction,
         eStartDocumentTransaction,
         eStartElementAtomTransaction,
         eStartElementTransaction
     };
     txOutputTransaction(txTransactionType aType)
         : mType(aType)
     {
+        MOZ_COUNT_CTOR(txOutputTransaction);
     }
     virtual ~txOutputTransaction()
     {
+        MOZ_COUNT_DTOR(txOutputTransaction);
     }
     txTransactionType mType;
 };
 
 class txCharacterTransaction : public txOutputTransaction
 {
 public:
     txCharacterTransaction(txTransactionType aType, PRUint32 aLength)
         : txOutputTransaction(aType),
           mLength(aLength)
     {
+        MOZ_COUNT_CTOR_INHERITED(txCharacterTransaction, txOutputTransaction);
+    }
+    virtual ~txCharacterTransaction()
+    {
+        MOZ_COUNT_DTOR_INHERITED(txCharacterTransaction, txOutputTransaction);
     }
     PRUint32 mLength;
 };
 
 class txCommentTransaction : public txOutputTransaction
 {
 public:
     txCommentTransaction(const nsAString& aValue)
         : txOutputTransaction(eCommentTransaction),
           mValue(aValue)
     {
+        MOZ_COUNT_CTOR_INHERITED(txCommentTransaction, txOutputTransaction);
+    }
+    virtual ~txCommentTransaction()
+    {
+        MOZ_COUNT_DTOR_INHERITED(txCommentTransaction, txOutputTransaction);
     }
     nsString mValue;
 };
 
 class txPITransaction : public txOutputTransaction
 {
 public:
     txPITransaction(const nsAString& aTarget, const nsAString& aData)
         : txOutputTransaction(ePITransaction),
           mTarget(aTarget),
           mData(aData)
     {
+        MOZ_COUNT_CTOR_INHERITED(txPITransaction, txOutputTransaction);
+    }
+    virtual ~txPITransaction()
+    {
+        MOZ_COUNT_DTOR_INHERITED(txPITransaction, txOutputTransaction);
     }
     nsString mTarget;
     nsString mData;
 };
 
 class txStartElementAtomTransaction : public txOutputTransaction
 {
 public:
     txStartElementAtomTransaction(nsIAtom* aPrefix, nsIAtom* aLocalName,
                                   nsIAtom* aLowercaseLocalName, PRInt32 aNsID)
         : txOutputTransaction(eStartElementAtomTransaction),
           mPrefix(aPrefix),
           mLocalName(aLocalName),
           mLowercaseLocalName(aLowercaseLocalName),
           mNsID(aNsID)
     {
+        MOZ_COUNT_CTOR_INHERITED(txStartElementAtomTransaction, txOutputTransaction);
+    }
+    virtual ~txStartElementAtomTransaction()
+    {
+        MOZ_COUNT_DTOR_INHERITED(txStartElementAtomTransaction, txOutputTransaction);
     }
     nsCOMPtr<nsIAtom> mPrefix;
     nsCOMPtr<nsIAtom> mLocalName;
     nsCOMPtr<nsIAtom> mLowercaseLocalName;
     PRInt32 mNsID;
 };
 
 class txStartElementTransaction : public txOutputTransaction
@@ -123,16 +145,21 @@ class txStartElementTransaction : public
 public:
     txStartElementTransaction(nsIAtom* aPrefix,
                               const nsSubstring& aLocalName, PRInt32 aNsID)
         : txOutputTransaction(eStartElementTransaction),
           mPrefix(aPrefix),
           mLocalName(aLocalName),
           mNsID(aNsID)
     {
+        MOZ_COUNT_CTOR_INHERITED(txStartElementTransaction, txOutputTransaction);
+    }
+    virtual ~txStartElementTransaction()
+    {
+        MOZ_COUNT_DTOR_INHERITED(txStartElementTransaction, txOutputTransaction);
     }
     nsCOMPtr<nsIAtom> mPrefix;
     nsString mLocalName;
     PRInt32 mNsID;
 };
 
 class txAttributeTransaction : public txOutputTransaction
 {
@@ -141,16 +168,21 @@ public:
                            const nsSubstring& aLocalName, PRInt32 aNsID,
                            const nsString& aValue)
         : txOutputTransaction(eAttributeTransaction),
           mPrefix(aPrefix),
           mLocalName(aLocalName),
           mNsID(aNsID),
           mValue(aValue)
     {
+        MOZ_COUNT_CTOR_INHERITED(txAttributeTransaction, txOutputTransaction);
+    }
+    virtual ~txAttributeTransaction()
+    {
+        MOZ_COUNT_DTOR_INHERITED(txAttributeTransaction, txOutputTransaction);
     }
     nsCOMPtr<nsIAtom> mPrefix;
     nsString mLocalName;
     PRInt32 mNsID;
     nsString mValue;
 };
 
 class txAttributeAtomTransaction : public txOutputTransaction
@@ -161,29 +193,40 @@ public:
                                PRInt32 aNsID, const nsString& aValue)
         : txOutputTransaction(eAttributeAtomTransaction),
           mPrefix(aPrefix),
           mLocalName(aLocalName),
           mLowercaseLocalName(aLowercaseLocalName),
           mNsID(aNsID),
           mValue(aValue)
     {
+        MOZ_COUNT_CTOR_INHERITED(txAttributeAtomTransaction, txOutputTransaction);
+    }
+    virtual ~txAttributeAtomTransaction()
+    {
+        MOZ_COUNT_DTOR_INHERITED(txAttributeAtomTransaction, txOutputTransaction);
     }
     nsCOMPtr<nsIAtom> mPrefix;
     nsCOMPtr<nsIAtom> mLocalName;
     nsCOMPtr<nsIAtom> mLowercaseLocalName;
     PRInt32 mNsID;
     nsString mValue;
 };
 
 txBufferingHandler::txBufferingHandler() : mCanAddAttribute(PR_FALSE)
 {
+    MOZ_COUNT_CTOR(txBufferingHandler);
     mBuffer = new txResultBuffer();
 }
 
+txBufferingHandler::~txBufferingHandler()
+{
+    MOZ_COUNT_DTOR(txBufferingHandler);
+}
+
 nsresult
 txBufferingHandler::attribute(nsIAtom* aPrefix, nsIAtom* aLocalName,
                               nsIAtom* aLowercaseLocalName, PRInt32 aNsID,
                               const nsString& aValue)
 {
     NS_ENSURE_TRUE(mBuffer, NS_ERROR_OUT_OF_MEMORY);
 
     if (!mCanAddAttribute) {
@@ -338,18 +381,24 @@ txBufferingHandler::startElement(nsIAtom
 
     txOutputTransaction* transaction =
         new txStartElementTransaction(aPrefix, aLocalName, aNsID);
     NS_ENSURE_TRUE(transaction, NS_ERROR_OUT_OF_MEMORY);
 
     return mBuffer->addTransaction(transaction);
 }
 
+txResultBuffer::txResultBuffer()
+{
+    MOZ_COUNT_CTOR(txResultBuffer);
+}
+
 txResultBuffer::~txResultBuffer()
 {
+    MOZ_COUNT_DTOR(txResultBuffer);
     for (PRUint32 i = 0, len = mTransactions.Length(); i < len; ++i) {
         delete mTransactions[i];
     }
 }
 
 nsresult
 txResultBuffer::addTransaction(txOutputTransaction* aTransaction)
 {
--- a/content/xslt/src/xslt/txBufferingHandler.h
+++ b/content/xslt/src/xslt/txBufferingHandler.h
@@ -46,16 +46,17 @@
 #include "nsAutoPtr.h"
 
 class txOutputTransaction;
 class txCharacterTransaction;
 
 class txResultBuffer
 {
 public:
+    txResultBuffer();
     ~txResultBuffer();
 
     nsresult addTransaction(txOutputTransaction* aTransaction);
 
     nsresult flushToHandler(txAXMLEventHandler* aHandler);
 
     txOutputTransaction* getLastTransaction();
 
@@ -64,16 +65,17 @@ public:
 private:
     nsTArray<txOutputTransaction*> mTransactions;
 };
 
 class txBufferingHandler : public txAXMLEventHandler
 {
 public:
     txBufferingHandler();
+    virtual ~txBufferingHandler();
 
     TX_DECL_TXAXMLEVENTHANDLER
 
 protected:
     nsAutoPtr<txResultBuffer> mBuffer;
     PRPackedBool mCanAddAttribute;
 };
 
--- a/content/xslt/src/xslt/txExecutionState.cpp
+++ b/content/xslt/src/xslt/txExecutionState.cpp
@@ -150,17 +150,17 @@ txExecutionState::init(const txXPathNode
 
     // Set up initial context
     mEvalContext = new txSingleNodeContext(aNode, this);
     NS_ENSURE_TRUE(mEvalContext, NS_ERROR_OUT_OF_MEMORY);
 
     mInitialEvalContext = mEvalContext;
 
     // Set up output and result-handler
-    txAXMLEventHandler* handler = 0;
+    txAXMLEventHandler* handler;
     rv = mOutputHandlerFactory->
         createHandlerWith(mStylesheet->getOutputFormat(), &handler);
     NS_ENSURE_SUCCESS(rv, rv);
 
     mOutputHandler = handler;
     mResultHandler = handler;
     mOutputHandler->startDocument();
 
--- a/content/xslt/src/xslt/txMozillaTextOutput.cpp
+++ b/content/xslt/src/xslt/txMozillaTextOutput.cpp
@@ -57,26 +57,33 @@
 #include "nsGkAtoms.h"
 
 using namespace mozilla::dom;
 
 txMozillaTextOutput::txMozillaTextOutput(nsIDOMDocument* aSourceDocument,
                                          nsIDOMDocument* aResultDocument,
                                          nsITransformObserver* aObserver)
 {
+    MOZ_COUNT_CTOR(txMozillaTextOutput);
     mObserver = do_GetWeakReference(aObserver);
     createResultDocument(aSourceDocument, aResultDocument);
 }
 
 txMozillaTextOutput::txMozillaTextOutput(nsIDOMDocumentFragment* aDest)
 {
+    MOZ_COUNT_CTOR(txMozillaTextOutput);
     mTextParent = do_QueryInterface(aDest);
     mDocument = mTextParent->GetOwnerDoc();
 }
 
+txMozillaTextOutput::~txMozillaTextOutput()
+{
+    MOZ_COUNT_DTOR(txMozillaTextOutput);
+}
+
 nsresult
 txMozillaTextOutput::attribute(nsIAtom* aPrefix, nsIAtom* aLocalName,
                                nsIAtom* aLowercaseLocalName,
                                PRInt32 aNsID, const nsString& aValue)
 {
     return NS_OK;
 }
 
--- a/content/xslt/src/xslt/txMozillaTextOutput.h
+++ b/content/xslt/src/xslt/txMozillaTextOutput.h
@@ -53,16 +53,17 @@ class nsIContent;
 
 class txMozillaTextOutput : public txAOutputXMLEventHandler
 {
 public:
     txMozillaTextOutput(nsIDOMDocument* aSourceDocument,
                         nsIDOMDocument* aResultDocument,
                         nsITransformObserver* aObserver);
     txMozillaTextOutput(nsIDOMDocumentFragment* aDest);
+    virtual ~txMozillaTextOutput();
 
     TX_DECL_TXAXMLEVENTHANDLER
     TX_DECL_TXAOUTPUTXMLEVENTHANDLER
 
 private:
     nsresult createResultDocument(nsIDOMDocument* aSourceDocument,
                                   nsIDOMDocument* aResultDocument);
     nsresult createXHTMLElement(nsIAtom* aName, nsIContent** aResult);
--- a/content/xslt/src/xslt/txMozillaXMLOutput.cpp
+++ b/content/xslt/src/xslt/txMozillaXMLOutput.cpp
@@ -89,16 +89,17 @@ txMozillaXMLOutput::txMozillaXMLOutput(c
     : mTreeDepth(0),
       mBadChildLevel(0),
       mTableState(NORMAL),
       mCreatingNewDocument(PR_TRUE),
       mOpenedElementIsHTML(PR_FALSE),
       mRootContentCreated(PR_FALSE),
       mNoFixup(PR_FALSE)
 {
+    MOZ_COUNT_CTOR(txMozillaXMLOutput);
     if (aObserver) {
         mNotifier = new txTransformNotifier();
         if (mNotifier) {
             mNotifier->Init(aObserver);
         }
     }
 
     mOutputFormat.merge(*aFormat);
@@ -113,29 +114,35 @@ txMozillaXMLOutput::txMozillaXMLOutput(t
     : mTreeDepth(0),
       mBadChildLevel(0),
       mTableState(NORMAL),
       mCreatingNewDocument(PR_FALSE),
       mOpenedElementIsHTML(PR_FALSE),
       mRootContentCreated(PR_FALSE),
       mNoFixup(aNoFixup)
 {
+    MOZ_COUNT_CTOR(txMozillaXMLOutput);
     mOutputFormat.merge(*aFormat);
     mOutputFormat.setFromDefaults();
 
     mCurrentNode = do_QueryInterface(aFragment);
     mDocument = mCurrentNode->GetOwnerDoc();
     if (mDocument) {
       mNodeInfoManager = mDocument->NodeInfoManager();
     }
     else {
       mCurrentNode = nsnull;
     }
 }
 
+txMozillaXMLOutput::~txMozillaXMLOutput()
+{
+    MOZ_COUNT_DTOR(txMozillaXMLOutput);
+}
+
 nsresult
 txMozillaXMLOutput::attribute(nsIAtom* aPrefix,
                               nsIAtom* aLocalName,
                               nsIAtom* aLowercaseLocalName,
                               const PRInt32 aNsID,
                               const nsString& aValue)
 {
     nsCOMPtr<nsIAtom> owner;
--- a/content/xslt/src/xslt/txMozillaXMLOutput.h
+++ b/content/xslt/src/xslt/txMozillaXMLOutput.h
@@ -97,16 +97,17 @@ public:
                        PRInt32 aRootNsID,
                        txOutputFormat* aFormat,
                        nsIDOMDocument* aSourceDocument,
                        nsIDOMDocument* aResultDocument,
                        nsITransformObserver* aObserver);
     txMozillaXMLOutput(txOutputFormat* aFormat,
                        nsIDOMDocumentFragment* aFragment,
                        PRBool aNoFixup);
+    ~txMozillaXMLOutput();
 
     TX_DECL_TXAXMLEVENTHANDLER
     TX_DECL_TXAOUTPUTXMLEVENTHANDLER
 
     nsresult closePrevious(PRBool aFlushText);
 
 private:
     nsresult createTxWrapper();
--- a/content/xslt/src/xslt/txUnknownHandler.cpp
+++ b/content/xslt/src/xslt/txUnknownHandler.cpp
@@ -40,16 +40,22 @@
 #include "txExecutionState.h"
 #include "txStringUtils.h"
 #include "txStylesheet.h"
 #include "txAtoms.h"
 
 txUnknownHandler::txUnknownHandler(txExecutionState* aEs)
     : mEs(aEs)
 {
+    MOZ_COUNT_CTOR_INHERITED(txUnknownHandler, txBufferingHandler);
+}
+
+txUnknownHandler::~txUnknownHandler()
+{
+    MOZ_COUNT_DTOR_INHERITED(txUnknownHandler, txBufferingHandler);
 }
 
 nsresult
 txUnknownHandler::endDocument(nsresult aResult)
 {
     if (NS_FAILED(aResult)) {
         return NS_OK;
     }
--- a/content/xslt/src/xslt/txUnknownHandler.h
+++ b/content/xslt/src/xslt/txUnknownHandler.h
@@ -43,16 +43,17 @@
 #include "txOutputFormat.h"
 
 class txExecutionState;
 
 class txUnknownHandler : public txBufferingHandler
 {
 public:
     txUnknownHandler(txExecutionState* aEs);
+    virtual ~txUnknownHandler();
 
     nsresult endDocument(nsresult aResult);
     nsresult startElement(nsIAtom* aPrefix, nsIAtom* aName,
                           nsIAtom* aLowercaseName, PRInt32 aNsID);
     nsresult startElement(nsIAtom* aPrefix, const nsSubstring& aLocalName,
                           const PRInt32 aNsID);
 
 private:
--- a/xpcom/glue/nsTraceRefcnt.h
+++ b/xpcom/glue/nsTraceRefcnt.h
@@ -48,38 +48,50 @@
 #define NS_LOG_RELEASE(_p, _rc, _type) \
   NS_LogRelease((_p), (_rc), (_type))
 
 #define MOZ_COUNT_CTOR(_type)                                 \
 PR_BEGIN_MACRO                                                \
   NS_LogCtor((void*)this, #_type, sizeof(*this));             \
 PR_END_MACRO
 
+#define MOZ_COUNT_CTOR_INHERITED(_type, _base)                    \
+PR_BEGIN_MACRO                                                    \
+  NS_LogCtor((void*)this, #_type, sizeof(*this) - sizeof(_base)); \
+PR_END_MACRO
+
 #define MOZ_COUNT_DTOR(_type)                                 \
 PR_BEGIN_MACRO                                                \
   NS_LogDtor((void*)this, #_type, sizeof(*this));             \
 PR_END_MACRO
 
+#define MOZ_COUNT_DTOR_INHERITED(_type, _base)                    \
+PR_BEGIN_MACRO                                                    \
+  NS_LogDtor((void*)this, #_type, sizeof(*this) - sizeof(_base)); \
+PR_END_MACRO
+
 /* nsCOMPtr.h allows these macros to be defined by clients
  * These logging functions require dynamic_cast<void*>, so they don't
  * do anything useful if we don't have dynamic_cast<void*>. */
 #define NSCAP_LOG_ASSIGNMENT(_c, _p)                                \
   if (_p)                                                           \
     NS_LogCOMPtrAddRef((_c),static_cast<nsISupports*>(_p))
 
 #define NSCAP_LOG_RELEASE(_c, _p)                                   \
   if (_p)                                                           \
     NS_LogCOMPtrRelease((_c), static_cast<nsISupports*>(_p))
 
 #else /* !NS_BUILD_REFCNT_LOGGING */
 
 #define NS_LOG_ADDREF(_p, _rc, _type, _size)
 #define NS_LOG_RELEASE(_p, _rc, _type)
 #define MOZ_COUNT_CTOR(_type)
+#define MOZ_COUNT_CTOR_INHERITED(_type, _base)
 #define MOZ_COUNT_DTOR(_type)
+#define MOZ_COUNT_DTOR_INHERITED(_type, _base)
 
 #endif /* NS_BUILD_REFCNT_LOGGING */
 
 #ifdef __cplusplus
 
 class nsTraceRefcnt {
 public:
   inline static void LogAddRef(void* aPtr, nsrefcnt aNewRefCnt,