Fixed leak in nsObserverList. Used nsObjectHashtable in service mgr implementation.

This commit is contained in:
warren%netscape.com 1999-07-30 07:58:55 +00:00
Родитель abb94bdcc3
Коммит 9b00e5191d
4 изменённых файлов: 24 добавлений и 12 удалений

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

@ -156,16 +156,9 @@ protected:
virtual ~nsServiceManagerImpl(void);
nsHashtable/*<nsServiceEntry>*/* mServices;
nsObjectHashtable/*<nsServiceEntry>*/* mServices;
};
nsServiceManagerImpl::nsServiceManagerImpl(void)
{
NS_INIT_REFCNT();
mServices = new nsHashtable(256, PR_TRUE); // Get a threadSafe hashtable
NS_ASSERTION(mServices, "out of memory already?");
}
static PRBool
DeleteEntry(nsHashKey *aKey, void *aData, void* closure)
{
@ -175,10 +168,18 @@ DeleteEntry(nsHashKey *aKey, void *aData, void* closure)
return PR_TRUE;
}
nsServiceManagerImpl::nsServiceManagerImpl(void)
{
NS_INIT_REFCNT();
mServices = new nsObjectHashtable(nsnull, nsnull, // should never be cloned
DeleteEntry, nsnull,
256, PR_TRUE); // Get a threadSafe hashtable
NS_ASSERTION(mServices, "out of memory already?");
}
nsServiceManagerImpl::~nsServiceManagerImpl(void)
{
if (mServices) {
mServices->Enumerate(DeleteEntry);
delete mServices;
}
}

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

@ -63,6 +63,7 @@ nsObserverList::nsObserverList()
nsObserverList::~nsObserverList(void)
{
PR_DestroyLock(mLock);
NS_IF_RELEASE(mObserverList);
}

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

@ -87,6 +87,14 @@ nsresult nsObserverService::GetObserverService(nsIObserverService** anObserverSe
return NS_OK;
}
static PRBool
ReleaseObserverList(nsHashKey *aKey, void *aData, void* closure)
{
nsIObserverList* observerList = NS_STATIC_CAST(nsIObserverList*, aData);
NS_RELEASE(observerList);
return PR_TRUE;
}
nsresult nsObserverService::GetObserverList(const nsString& aTopic, nsIObserverList** anObserverList)
{
if (anObserverList == NULL)
@ -95,7 +103,9 @@ nsresult nsObserverService::GetObserverList(const nsString& aTopic, nsIObserverL
}
if(mObserverTopicTable == NULL) {
mObserverTopicTable = new nsHashtable(256, PR_TRUE);
mObserverTopicTable = new nsObjectHashtable(nsnull, nsnull, // should never be cloned
ReleaseObserverList, nsnull,
256, PR_TRUE);
if (mObserverTopicTable == NULL)
return NS_ERROR_OUT_OF_MEMORY;
}

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

@ -22,7 +22,7 @@
#include "nsIObserverService.h"
#include "nsIObserverList.h"
class nsHashtable;
class nsObjectHashtable;
class nsString;
// {D07F5195-E3D1-11d2-8ACD-00105A1B8860}
@ -49,7 +49,7 @@ private:
NS_IMETHOD GetObserverList(const nsString& aTopic, nsIObserverList** anObserverList);
nsHashtable* mObserverTopicTable;
nsObjectHashtable* mObserverTopicTable;
};