diff --git a/toolkit/xre/nsQAppInstance.cpp b/toolkit/xre/nsQAppInstance.cpp index 4be12c96158e..76558e63412d 100644 --- a/toolkit/xre/nsQAppInstance.cpp +++ b/toolkit/xre/nsQAppInstance.cpp @@ -11,6 +11,7 @@ #include #endif #include "prenv.h" +#include "nsXPCOMPrivate.h" #include QApplication *nsQAppInstance::sQAppInstance = nullptr; @@ -29,6 +30,7 @@ void nsQAppInstance::AddRef(int& aArgc, char** aArgv, bool aDefaultProcess) { QApplication::setGraphicsSystem(QString(graphicsSystem)); } #endif + mozilla::SetICUMemoryFunctions(); sQAppInstance = new QApplication(aArgc, aArgv); } sQAppRefCount++; diff --git a/xpcom/build/nsXPCOMPrivate.h b/xpcom/build/nsXPCOMPrivate.h index 7f6ed3a35061..c15865a5445e 100644 --- a/xpcom/build/nsXPCOMPrivate.h +++ b/xpcom/build/nsXPCOMPrivate.h @@ -194,6 +194,8 @@ namespace mozilla { nsresult ShutdownXPCOM(nsIServiceManager* servMgr); +void SetICUMemoryFunctions(); + /** * C++ namespaced version of NS_LogTerm. */ diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp index b314b0c080c7..3b58e19f1a71 100644 --- a/xpcom/build/nsXPComInit.cpp +++ b/xpcom/build/nsXPComInit.cpp @@ -554,10 +554,7 @@ NS_InitXPCOM2(nsIServiceManager* *result, // can't define the alloc/free functions in the JS engine, because it can't // depend on the XPCOM-based memory reporting goop. So for now, we have // this oddness. - if (!JS_SetICUMemoryFunctions(ICUReporter::Alloc, ICUReporter::Realloc, - ICUReporter::Free)) { - NS_RUNTIMEABORT("JS_SetICUMemoryFunctions failed."); - } + mozilla::SetICUMemoryFunctions(); // Initialize the JS engine. if (!JS_Init()) { @@ -658,6 +655,19 @@ NS_ShutdownXPCOM(nsIServiceManager* servMgr) namespace mozilla { +void +SetICUMemoryFunctions() +{ + static bool sICUReporterInitialized = false; + if (!sICUReporterInitialized) { + if (!JS_SetICUMemoryFunctions(ICUReporter::Alloc, ICUReporter::Realloc, + ICUReporter::Free)) { + NS_RUNTIMEABORT("JS_SetICUMemoryFunctions failed."); + } + sICUReporterInitialized = true; + } +} + nsresult ShutdownXPCOM(nsIServiceManager* servMgr) {