From 86bd6bd89c4d1bf6c27751cbd93dda6062be05a1 Mon Sep 17 00:00:00 2001 From: "akkana%netscape.com" Date: Fri, 18 Jun 1999 21:10:59 +0000 Subject: [PATCH] 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. git-svn-id: svn://10.0.0.236/trunk@35876 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsEditFactory.cpp | 24 ++++++++++++-------- mozilla/editor/base/nsEditorShellFactory.cpp | 20 ++++++++-------- mozilla/editor/base/nsHTMLEditFactory.cpp | 20 ++++++++-------- mozilla/editor/base/nsTextEditFactory.cpp | 20 ++++++++-------- 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/mozilla/editor/base/nsEditFactory.cpp b/mozilla/editor/base/nsEditFactory.cpp index e4092384a49..d06f1fd3049 100644 --- a/mozilla/editor/base/nsEditFactory.cpp +++ b/mozilla/editor/base/nsEditFactory.cpp @@ -30,17 +30,21 @@ static NS_DEFINE_CID(kEditorCID, NS_EDITOR_CID); nsresult GetEditFactory(nsIFactory **aFactory, const nsCID & aClass) { - static nsCOMPtr 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 pNSIFactory = do_QueryInterface(factory); + if (!pNSIFactory) + return NS_ERROR_NO_INTERFACE; + + nsresult result = pNSIFactory->QueryInterface(nsIFactory::GetIID(), + (void **)aFactory); PR_ExitMonitor(GetEditorMonitor()); return result; } diff --git a/mozilla/editor/base/nsEditorShellFactory.cpp b/mozilla/editor/base/nsEditorShellFactory.cpp index a2d29142a99..dc43913b180 100644 --- a/mozilla/editor/base/nsEditorShellFactory.cpp +++ b/mozilla/editor/base/nsEditorShellFactory.cpp @@ -128,17 +128,17 @@ nsEditorShellFactoryImpl::LockFactory(PRBool aLock) nsresult GetEditorShellFactory(nsIFactory **aFactory, const nsCID &aClass, const char *aClassName, const char *aProgID) { - static nsCOMPtr 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 pNSIFactory (do_QueryInterface(factory)); + if (!pNSIFactory) + return NS_ERROR_NO_INTERFACE; + + nsresult result = pNSIFactory->QueryInterface(kIFactoryIID, + (void **)aFactory); PR_ExitMonitor(GetEditorMonitor()); return result; } diff --git a/mozilla/editor/base/nsHTMLEditFactory.cpp b/mozilla/editor/base/nsHTMLEditFactory.cpp index 4992cfdcd07..390ccec9466 100644 --- a/mozilla/editor/base/nsHTMLEditFactory.cpp +++ b/mozilla/editor/base/nsHTMLEditFactory.cpp @@ -33,17 +33,17 @@ static NS_DEFINE_IID(kIHTMLEditFactoryIID, NS_IHTMLEDITORFACTORY_IID); nsresult GetHTMLEditFactory(nsIFactory **aFactory, const nsCID & aClass) { - static nsCOMPtr 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 pNSIFactory = do_QueryInterface(factory); + if (!pNSIFactory) + return NS_ERROR_NO_INTERFACE; + + nsresult result = pNSIFactory->QueryInterface(kIFactoryIID, + (void **)aFactory); PR_ExitMonitor(GetEditorMonitor()); return result; } diff --git a/mozilla/editor/base/nsTextEditFactory.cpp b/mozilla/editor/base/nsTextEditFactory.cpp index b3713458973..7747ef9a852 100644 --- a/mozilla/editor/base/nsTextEditFactory.cpp +++ b/mozilla/editor/base/nsTextEditFactory.cpp @@ -30,17 +30,17 @@ static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID); nsresult GetTextEditFactory(nsIFactory **aFactory, const nsCID & aClass) { - static nsCOMPtr 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 pNSIFactory = do_QueryInterface(factory); + if (!pNSIFactory) + return NS_ERROR_NO_INTERFACE; + + nsresult result = pNSIFactory->QueryInterface(nsIFactory::GetIID(), + (void **)aFactory); PR_ExitMonitor(GetEditorMonitor()); return result; }