Eliminate static nsCOMPtr variables in editor factory classes.

These were causing a crash on exit, bug 7938.
Approved by chofmann; Reviewed in concept by dp,
in detail by braddr@portland.puremagic.com and sfraser.
This commit is contained in:
akkana%netscape.com 1999-06-18 21:10:59 +00:00
parent 7f8e5e2973
commit 92ed1fb8a0
4 changed files with 44 additions and 40 deletions

View File

@ -30,17 +30,21 @@ static NS_DEFINE_CID(kEditorCID, NS_EDITOR_CID);
nsresult
GetEditFactory(nsIFactory **aFactory, const nsCID & aClass)
{
static nsCOMPtr<nsIFactory> g_pNSIFactory;
// XXX Note static which never gets released, even on library unload.
// XXX Was an nsCOMPtr but that caused a crash on exit,
// XXX http://bugzilla.mozilla.org/show_bug.cgi?id=7938
PR_EnterMonitor(GetEditorMonitor());
nsresult result = NS_ERROR_FAILURE;
if (!g_pNSIFactory)
{
nsEditFactory *factory = new nsEditFactory(aClass);
g_pNSIFactory = do_QueryInterface(factory);
if (factory)
result = NS_OK;
}
result = g_pNSIFactory->QueryInterface(nsIFactory::GetIID(), (void **)aFactory);
nsEditFactory *factory = new nsEditFactory(aClass);
if (!factory)
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIFactory> pNSIFactory = do_QueryInterface(factory);
if (!pNSIFactory)
return NS_ERROR_NO_INTERFACE;
nsresult result = pNSIFactory->QueryInterface(nsIFactory::GetIID(),
(void **)aFactory);
PR_ExitMonitor(GetEditorMonitor());
return result;
}

View File

@ -128,17 +128,17 @@ nsEditorShellFactoryImpl::LockFactory(PRBool aLock)
nsresult
GetEditorShellFactory(nsIFactory **aFactory, const nsCID &aClass, const char *aClassName, const char *aProgID)
{
static nsCOMPtr<nsIFactory> g_pNSIFactory;
PR_EnterMonitor(GetEditorMonitor());
nsresult result = NS_ERROR_FAILURE;
if (!g_pNSIFactory)
{
nsEditorShellFactoryImpl* factory = new nsEditorShellFactoryImpl(aClass, aClassName, aProgID);
g_pNSIFactory = do_QueryInterface(factory);
if (factory)
result = NS_OK;
}
result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory);
nsEditorShellFactoryImpl* factory = new nsEditorShellFactoryImpl(aClass, aClassName, aProgID);
if (!factory)
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIFactory> pNSIFactory (do_QueryInterface(factory));
if (!pNSIFactory)
return NS_ERROR_NO_INTERFACE;
nsresult result = pNSIFactory->QueryInterface(kIFactoryIID,
(void **)aFactory);
PR_ExitMonitor(GetEditorMonitor());
return result;
}

View File

@ -33,17 +33,17 @@ static NS_DEFINE_IID(kIHTMLEditFactoryIID, NS_IHTMLEDITORFACTORY_IID);
nsresult
GetHTMLEditFactory(nsIFactory **aFactory, const nsCID & aClass)
{
static nsCOMPtr<nsIFactory> g_pNSIFactory;
PR_EnterMonitor(GetEditorMonitor());
nsresult result = NS_ERROR_FAILURE;
if (!g_pNSIFactory)
{
nsHTMLEditFactory *factory = new nsHTMLEditFactory(aClass);
g_pNSIFactory = do_QueryInterface(factory);
if (factory)
result = NS_OK;
}
result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory);
nsHTMLEditFactory *factory = new nsHTMLEditFactory(aClass);
if (!factory)
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIFactory> pNSIFactory = do_QueryInterface(factory);
if (!pNSIFactory)
return NS_ERROR_NO_INTERFACE;
nsresult result = pNSIFactory->QueryInterface(kIFactoryIID,
(void **)aFactory);
PR_ExitMonitor(GetEditorMonitor());
return result;
}

View File

@ -30,17 +30,17 @@ static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
nsresult
GetTextEditFactory(nsIFactory **aFactory, const nsCID & aClass)
{
static nsCOMPtr<nsIFactory> g_pNSIFactory;
PR_EnterMonitor(GetEditorMonitor());
nsresult result = NS_ERROR_FAILURE;
if (!g_pNSIFactory)
{
nsTextEditFactory *factory = new nsTextEditFactory(aClass);
g_pNSIFactory = do_QueryInterface(factory);
if (factory)
result = NS_OK;
}
result = g_pNSIFactory->QueryInterface(nsIFactory::GetIID(), (void **)aFactory);
nsTextEditFactory *factory = new nsTextEditFactory(aClass);
if (factory)
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIFactory> pNSIFactory = do_QueryInterface(factory);
if (!pNSIFactory)
return NS_ERROR_NO_INTERFACE;
nsresult result = pNSIFactory->QueryInterface(nsIFactory::GetIID(),
(void **)aFactory);
PR_ExitMonitor(GetEditorMonitor());
return result;
}