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; }