Fix scrollbar leaks by making sure that we decrement the refcnt when Destroy() is called.

bug #101814 r=pavlov
This commit is contained in:
seawood%netscape.com 2001-10-13 05:50:16 +00:00
Родитель 94b39f0b80
Коммит 489a2c4aec
2 изменённых файлов: 22 добавлений и 22 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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);