Bug 429233 - Firefox leaks nsTArray_base due to nsDOMKeyboardEvent's dtor not being virtual; also makes ~nsEvent virtual as well and uses MOZ_COUNT_[CD]TOR in nsEvent. Patch by Ben Turner <bent.mozilla@gmail.com>, r+sr=jst, a=beltzner
authorjwalden@mit.edu
Thu, 17 Apr 2008 15:38:35 -0700
changeset 14438 4ba52349a1bace18a0c3a06becb241dc9f2737c1
parent 14437 88f8ba037468cf1855fb11c9164016822762521c
child 14439 b32e34d8dac0608526c62d9adcac3d3c927ea9cc
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbeltzner
bugs429233
milestone1.9pre
Bug 429233 - Firefox leaks nsTArray_base due to nsDOMKeyboardEvent's dtor not being virtual; also makes ~nsEvent virtual as well and uses MOZ_COUNT_[CD]TOR in nsEvent. Patch by Ben Turner <bent.mozilla@gmail.com>, r+sr=jst, a=beltzner
content/events/src/nsDOMKeyboardEvent.cpp
content/events/src/nsDOMKeyboardEvent.h
widget/public/nsGUIEvent.h
--- a/content/events/src/nsDOMKeyboardEvent.cpp
+++ b/content/events/src/nsDOMKeyboardEvent.cpp
@@ -52,16 +52,24 @@ nsDOMKeyboardEvent::nsDOMKeyboardEvent(n
     mEventIsInternal = PR_FALSE;
   }
   else {
     mEventIsInternal = PR_TRUE;
     mEvent->time = PR_Now();
   }
 }
 
+nsDOMKeyboardEvent::~nsDOMKeyboardEvent()
+{
+  if (mEventIsInternal) {
+    delete static_cast<nsKeyEvent*>(mEvent);
+    mEvent = nsnull;
+  }
+}
+
 NS_IMPL_ADDREF_INHERITED(nsDOMKeyboardEvent, nsDOMUIEvent)
 NS_IMPL_RELEASE_INHERITED(nsDOMKeyboardEvent, nsDOMUIEvent)
 
 NS_INTERFACE_MAP_BEGIN(nsDOMKeyboardEvent)
   NS_INTERFACE_MAP_ENTRY(nsIDOMKeyEvent)
   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(KeyboardEvent)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
 
--- a/content/events/src/nsDOMKeyboardEvent.h
+++ b/content/events/src/nsDOMKeyboardEvent.h
@@ -42,16 +42,17 @@
 #include "nsIDOMKeyEvent.h"
 #include "nsDOMUIEvent.h"
 
 class nsDOMKeyboardEvent : public nsIDOMKeyEvent,
                            public nsDOMUIEvent
 {
 public:
   nsDOMKeyboardEvent(nsPresContext* aPresContext, nsKeyEvent* aEvent);
+  virtual ~nsDOMKeyboardEvent();
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMKeyEvent Interface
   NS_DECL_NSIDOMKEYEVENT
 
   // Forward to base class
   NS_FORWARD_TO_NSDOMUIEVENT
--- a/widget/public/nsGUIEvent.h
+++ b/widget/public/nsGUIEvent.h
@@ -52,16 +52,17 @@
 #undef ERROR
 #endif
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
 #include "nsIDOMKeyEvent.h"
 #include "nsWeakPtr.h"
 #include "nsIWidget.h"
 #include "nsTArray.h"
+#include "nsTraceRefcnt.h"
 
 class nsIRenderingContext;
 class nsIRegion;
 class nsIMenuItem;
 class nsIAccessible;
 class nsIContent;
 class nsIURI;
 class nsIDOMEvent;
@@ -389,27 +390,34 @@ protected:
   nsEvent(PRBool isTrusted, PRUint32 msg, PRUint8 structType)
     : eventStructType(structType),
       message(msg),
       refPoint(0, 0),
       time(0),
       flags(isTrusted ? NS_EVENT_FLAG_TRUSTED : NS_EVENT_FLAG_NONE),
       userType(0)
   {
+    MOZ_COUNT_CTOR(nsEvent);
   }
 
 public:
   nsEvent(PRBool isTrusted, PRUint32 msg)
     : eventStructType(NS_EVENT),
       message(msg),
       refPoint(0, 0),
       time(0),
       flags(isTrusted ? NS_EVENT_FLAG_TRUSTED : NS_EVENT_FLAG_NONE),
       userType(0)
   {
+    MOZ_COUNT_CTOR(nsEvent);
+  }
+
+  ~nsEvent()
+  {
+    MOZ_COUNT_DTOR(nsEvent);
   }
 
   // See event struct types
   PRUint8     eventStructType;
   // See GUI MESSAGES,
   PRUint32    message;
   // In widget relative coordinates, not modified by layout code.
   nsPoint     refPoint;