Fix various shutdown leaks. b=179361 r=blizzard sr=bryner

This commit is contained in:
dbaron%fas.harvard.edu 2002-11-13 03:01:08 +00:00
parent c1a28934d4
commit c67e79f291
9 changed files with 73 additions and 12 deletions

View File

@ -297,6 +297,7 @@ nsGfxGTKModuleDtor(nsIModule *self)
{
nsRenderingContextGTK::Shutdown();
nsDeviceContextGTK::Shutdown();
nsImageGTK::Shutdown();
nsGCCache::Shutdown();
#ifdef MOZ_WIDGET_GTK
nsRegionGTK::Shutdown();

View File

@ -124,6 +124,19 @@ nsImageGTK::~nsImageGTK()
#endif
}
/* static */ void
nsImageGTK::Shutdown()
{
if (s1bitGC) {
gdk_gc_unref(s1bitGC);
s1bitGC = nsnull;
}
if (sXbitGC) {
gdk_gc_unref(sXbitGC);
sXbitGC = nsnull;
}
}
//------------------------------------------------------------
nsresult nsImageGTK::Init(PRInt32 aWidth, PRInt32 aHeight,

View File

@ -54,6 +54,8 @@ public:
nsImageGTK();
virtual ~nsImageGTK();
static void Shutdown();
NS_DECL_ISUPPORTS
/**

View File

@ -157,8 +157,23 @@ nsAppShell::~nsAppShell()
#ifdef DEBUG_APPSHELL
printf("nsAppShell::~nsAppShell()\n");
#endif
// XXX we need to free this hashtable
// PL_HashTableDestroy(sQueueHashTable);
}
/* static */ void
nsAppShell::ReleaseGlobals()
{
if (sQueueHashTable) {
PL_HashTableDestroy(sQueueHashTable);
sQueueHashTable = nsnull;
}
if (sCountHashTable) {
PL_HashTableDestroy(sCountHashTable);
sCountHashTable = nsnull;
}
if (sEventQueueList) {
delete sEventQueueList;
sEventQueueList = nsnull;
}
}
//-------------------------------------------------------------------------

View File

@ -51,6 +51,8 @@ public:
nsAppShell();
virtual ~nsAppShell();
static void ReleaseGlobals();
NS_DECL_ISUPPORTS
NS_DECL_NSIAPPSHELL

View File

@ -36,7 +36,9 @@
static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
#ifdef PR_LOGGING
static PRLogModuleInfo *sDragLm = NULL;
#endif
static const char gMimeListType[] = "application/x-moz-internal-item-list";
static const char gMozUrlType[] = "_NETSCAPE_URL";
@ -75,8 +77,10 @@ nsDragService::nsDragService()
GTK_SIGNAL_FUNC(invisibleSourceDragEnd), this);
// set up our logging module
#ifdef PR_LOGGING
if (!sDragLm)
sDragLm = PR_NewLogModule("nsDragService");
#endif
PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::nsDragService"));
mTargetWidget = 0;
mTargetDragContext = 0;
@ -91,7 +95,7 @@ nsDragService::nsDragService()
nsDragService::~nsDragService()
{
PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::~nsDragService"));
gtk_widget_destroy(mHiddenWidget);
gtk_widget_unref(mHiddenWidget);
TargetResetData();
}

View File

@ -232,7 +232,8 @@ static const nsModuleComponentInfo components[] =
PR_STATIC_CALLBACK(void)
nsWidgetGTKModuleDtor(nsIModule *self)
{
nsWindow::FreeIconCache();
nsWindow::ReleaseGlobals();
nsAppShell::ReleaseGlobals();
nsGtkIMEHelper::Shutdown();
}

View File

@ -124,6 +124,8 @@ static PRBool gRaiseWindows = PR_TRUE;
/* cursors cache */
GdkCursor *nsWindow::gsGtkCursorCache[eCursor_count_up_down + 1];
#define ARRAY_LENGTH(a) (sizeof(a)/sizeof(a[0]))
/* window icon cache */
struct IconEntry : public PLDHashEntryHdr {
const char* string;
@ -357,6 +359,33 @@ nsWindow::~nsWindow()
UnqueueDraw();
}
/* static */ void
nsWindow::ReleaseGlobals()
{
if (gXICLookupTable.ops) {
PL_DHashTableFinish(&gXICLookupTable);
gXICLookupTable.ops = nsnull;
}
if (sIconCache) {
PL_DHashTableDestroy(sIconCache);
sIconCache = nsnull;
}
if (gPreeditFontset) {
gdk_font_unref(gPreeditFontset);
gPreeditFontset = nsnull;
}
if (gStatusFontset) {
gdk_font_unref(gStatusFontset);
gStatusFontset = nsnull;
}
for (int i = 0; i < ARRAY_LENGTH(gsGtkCursorCache); ++i) {
if (gsGtkCursorCache[i]) {
gdk_cursor_destroy(gsGtkCursorCache[i]);
gsGtkCursorCache[i] = nsnull;
}
}
}
NS_IMETHODIMP nsWindow::Destroy(void)
{
// remove our pointer from the object so that we event handlers don't send us events
@ -4288,10 +4317,3 @@ nsWindow::ClearIconEntry(PLDHashTable* aTable, PLDHashEntryHdr* aHdr)
free((void*) entry->string);
PL_DHashClearEntryStub(aTable, aHdr);
}
void
nsWindow::FreeIconCache()
{
if (sIconCache)
PL_DHashTableDestroy(sIconCache);
}

View File

@ -70,6 +70,8 @@ public:
nsWindow();
virtual ~nsWindow();
static void ReleaseGlobals();
NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD WidgetToScreen(const nsRect &aOldRect, nsRect &aNewRect);
@ -194,7 +196,6 @@ public:
const PLDHashEntryHdr* aHdr,
const void* aKey);
static void ClearIconEntry(PLDHashTable* aTable, PLDHashEntryHdr* aHdr);
static void FreeIconCache(void);
protected: