Bug 1335235: Add disabling of the COM BSTR cache to mscom::MainThreadRuntime; r?jimm
MozReview-Commit-ID: 5RQvHiBoD2B
--- a/ipc/mscom/MainThreadRuntime.cpp
+++ b/ipc/mscom/MainThreadRuntime.cpp
@@ -25,16 +25,19 @@ struct LocalFreeDeleter
void operator()(void* aPtr)
{
::LocalFree(aPtr);
}
};
} // anonymous namespace
+// This API from oleaut32.dll is not declared in Windows SDK headers
+extern "C" void __cdecl SetOaNoCache(void);
+
namespace mozilla {
namespace mscom {
MainThreadRuntime::MainThreadRuntime()
: mInitResult(E_UNEXPECTED)
{
// We must be the outermost COM initialization on this thread. The COM runtime
// cannot be configured once we start manipulating objects
@@ -54,19 +57,23 @@ MainThreadRuntime::MainThreadRuntime()
mInitResult = ::CoCreateInstance(CLSID_GlobalOptions, nullptr,
CLSCTX_INPROC_SERVER, IID_IGlobalOptions,
(void**)getter_AddRefs(globalOpts));
MOZ_ASSERT(SUCCEEDED(mInitResult));
if (FAILED(mInitResult)) {
return;
}
+ // Disable COM's catch-all exception handler
mInitResult = globalOpts->Set(COMGLB_EXCEPTION_HANDLING,
COMGLB_EXCEPTION_DONOT_HANDLE_ANY);
MOZ_ASSERT(SUCCEEDED(mInitResult));
+
+ // Disable the BSTR cache (as it never invalidates, thus leaking memory)
+ ::SetOaNoCache();
}
HRESULT
MainThreadRuntime::InitializeSecurity()
{
HANDLE rawToken = nullptr;
BOOL ok = ::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &rawToken);
if (!ok) {