From 2ae055c74411e652b06bcbc3be423f90adca0a54 Mon Sep 17 00:00:00 2001 From: "seawood%netscape.com" Date: Sat, 13 Oct 2001 05:50:16 +0000 Subject: [PATCH] Fix scrollbar leaks by making sure that we decrement the refcnt when Destroy() is called. bug #101814 r=pavlov --- widget/src/beos/nsScrollbar.cpp | 32 ++++++++++++++++---------------- widget/src/beos/nsScrollbar.h | 12 ++++++------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/widget/src/beos/nsScrollbar.cpp b/widget/src/beos/nsScrollbar.cpp index 4cefe780e316..00f743765781 100644 --- a/widget/src/beos/nsScrollbar.cpp +++ b/widget/src/beos/nsScrollbar.cpp @@ -35,14 +35,22 @@ * * ***** END LICENSE BLOCK ***** */ +#include "nsISupportsUtils.h" +#include "nsWidgetsCID.h" #include "nsScrollbar.h" #include "nsToolkit.h" #include "nsGUIEvent.h" #include "nsUnitConversion.h" +//------------------------------------------------------------------------- +// +// nsISupports +// +//------------------------------------------------------------------------- NS_IMPL_ADDREF(nsScrollbar) NS_IMPL_RELEASE(nsScrollbar) +NS_IMPL_QUERY_INTERFACE2(nsScrollbar, nsIScrollbar, nsWindow) //------------------------------------------------------------------------- // @@ -54,6 +62,7 @@ nsScrollbar::nsScrollbar(PRBool aIsVertical) : nsWindow(), nsIScrollbar() NS_INIT_REFCNT(); mOrientation = (aIsVertical) ? B_VERTICAL : B_HORIZONTAL; mLineIncrement = 0; + mScrollbar = 0; thumb = 0; } @@ -69,25 +78,16 @@ nsScrollbar::~nsScrollbar() //------------------------------------------------------------------------- -// -// Query interface implementation -// +// Handle Destroy() here so that we properly Release() the instance +// and mScrollbar is destroyed by nsWindow::Destroy even though +// mScrollbar is non-zero after the call //------------------------------------------------------------------------- -nsresult nsScrollbar::QueryInterface(const nsIID& aIID, void** aInstancePtr) -{ - nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr); - - static NS_DEFINE_IID(kInsScrollbarIID, NS_ISCROLLBAR_IID); - if (result == NS_NOINTERFACE && aIID.Equals(kInsScrollbarIID)) { - *aInstancePtr = (void*) ((nsIScrollbar*)this); - NS_ADDREF_THIS(); - result = NS_OK; - } - - return result; +NS_METHOD nsScrollbar::Destroy() { + nsWindow::Destroy(); + NS_RELEASE_THIS(); + return NS_OK; } - //------------------------------------------------------------------------- // // Define the range settings diff --git a/widget/src/beos/nsScrollbar.h b/widget/src/beos/nsScrollbar.h index ebb58c239c2d..54aebe23f64e 100644 --- a/widget/src/beos/nsScrollbar.h +++ b/widget/src/beos/nsScrollbar.h @@ -38,6 +38,7 @@ #ifndef nsScrollbar_h__ #define nsScrollbar_h__ +#include "nsISupportsUtils.h" #include "nsdefs.h" #include "nsWindow.h" #include "nsSwitchToUIThread.h" @@ -49,22 +50,21 @@ class nsScrollbarBeOS; /** - * Native WIN32 scrollbar wrapper. + * Native BeOS scrollbar wrapper. */ class nsScrollbar : public nsWindow, public nsIScrollbar { + // nsISupports + NS_DECL_ISUPPORTS + public: nsScrollbar(PRBool aIsVertical); virtual ~nsScrollbar(); - // nsISupports - NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); - NS_IMETHOD_(nsrefcnt) AddRef(void); - NS_IMETHOD_(nsrefcnt) Release(void); - + NS_IMETHOD Destroy(void); // nsIScrollBar implementation NS_IMETHOD SetMaxRange(PRUint32 aEndRange); NS_IMETHOD GetMaxRange(PRUint32& aMaxRange);