mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Fixed leak in nsObserverList. Used nsObjectHashtable in service mgr implementation.
This commit is contained in:
parent
abb94bdcc3
commit
9b00e5191d
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user