Bug 1335235 - Add disabling of the COM BSTR cache to mscom::MainThreadRuntime. r=jimm, a=lizzard
authorAaron Klotz <aklotz@mozilla.com>
Mon, 30 Jan 2017 16:39:08 -0700
changeset 378953 c9a2f2cda1199ea76b8181f609028c07c906daaa
parent 378952 dd6cf0b21528034f95953aa6a9b4324fcadb1685
child 378954 69e5687ef053379e8044dbc38e3f3ec51a1f426a
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, lizzard
bugs1335235
milestone53.0
Bug 1335235 - Add disabling of the COM BSTR cache to mscom::MainThreadRuntime. r=jimm, a=lizzard MozReview-Commit-ID: 5RQvHiBoD2B
ipc/mscom/MainThreadRuntime.cpp
--- 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) {