mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-12 09:01:16 +00:00
fixed problem of gImageManager becoming a dnagling reference to a dead object
by adding an additional reference to the global image manager when it is created. current solution is that suggested by adam locke, but this really needs to be a service so that we don't leak memory. also made destructor virtual to correct warning pointed out by bruce@cybersight.com.
This commit is contained in:
parent
90145235d4
commit
4c6288cc8a
@ -27,7 +27,7 @@ static NS_DEFINE_IID(kIImageManagerIID, NS_IIMAGEMANAGER_IID);
|
||||
class ImageManagerImpl : public nsIImageManager {
|
||||
public:
|
||||
ImageManagerImpl();
|
||||
~ImageManagerImpl();
|
||||
virtual ~ImageManagerImpl();
|
||||
|
||||
nsresult Init();
|
||||
|
||||
@ -44,6 +44,10 @@ private:
|
||||
ilISystemServices *mSS;
|
||||
};
|
||||
|
||||
// The singleton image manager
|
||||
// XXX make this a service
|
||||
static ImageManagerImpl* gImageManager;
|
||||
|
||||
ImageManagerImpl::ImageManagerImpl()
|
||||
{
|
||||
NS_NewImageSystemServices(&mSS);
|
||||
@ -56,9 +60,20 @@ ImageManagerImpl::~ImageManagerImpl()
|
||||
{
|
||||
IL_Shutdown();
|
||||
NS_RELEASE(mSS);
|
||||
// gImageManager = nsnull;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ImageManagerImpl, kIImageManagerIID)
|
||||
NS_IMPL_ADDREF(ImageManagerImpl)
|
||||
NS_IMPL_QUERY_INTERFACE(ImageManagerImpl, kIImageManagerIID)
|
||||
|
||||
nsrefcnt ImageManagerImpl::Release(void)
|
||||
{
|
||||
if (--mRefCnt == 0) {
|
||||
NS_DELETEXPCOM(this);
|
||||
return 0;
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ImageManagerImpl::Init()
|
||||
@ -108,10 +123,6 @@ ImageManagerImpl::GetImageType(const char *buf, PRInt32 length)
|
||||
}
|
||||
}
|
||||
|
||||
// The singleton image manager
|
||||
// XXX make this a service
|
||||
static ImageManagerImpl* gImageManager;
|
||||
|
||||
extern "C" NS_GFX_(nsresult)
|
||||
NS_NewImageManager(nsIImageManager **aInstancePtrResult)
|
||||
{
|
||||
@ -121,6 +132,7 @@ NS_NewImageManager(nsIImageManager **aInstancePtrResult)
|
||||
}
|
||||
if (nsnull == gImageManager) {
|
||||
gImageManager = new ImageManagerImpl();
|
||||
NS_IF_ADDREF(gImageManager);
|
||||
}
|
||||
if (nsnull == gImageManager) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
Loading…
Reference in New Issue
Block a user