From 4c6288cc8a7a83e38e9e0e10e3fc553c6317f26f Mon Sep 17 00:00:00 2001 From: "michaelp%netscape.com" Date: Tue, 30 Mar 1999 01:43:32 +0000 Subject: [PATCH] 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. --- gfx/src/nsImageManager.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gfx/src/nsImageManager.cpp b/gfx/src/nsImageManager.cpp index f6c8a29a3eaf..915626a85196 100644 --- a/gfx/src/nsImageManager.cpp +++ b/gfx/src/nsImageManager.cpp @@ -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;