Bug 1131871 - auto_com should only uninitialize when successful. r=padenot

--HG--
extra : rebase_source : 4af27a3e50b68ad1ee4d869b1a3bee3eeb4a1141
This commit is contained in:
David Major 2015-02-12 10:33:45 +13:00
parent 332621b1f2
commit a5abfe834e

View File

@ -164,7 +164,7 @@ private:
struct auto_com { struct auto_com {
auto_com() auto_com()
: need_uninit(true) { : need_uninit(false) {
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
// This is for information purposes only, in anycase, COM is initialized // This is for information purposes only, in anycase, COM is initialized
// at the end of the constructor. // at the end of the constructor.
@ -172,14 +172,15 @@ struct auto_com {
// This is an error, COM was not initialized by this function, so it is // This is an error, COM was not initialized by this function, so it is
// not necessary to uninit it. // not necessary to uninit it.
LOG("COM already initialized in STA."); LOG("COM already initialized in STA.");
need_uninit = false;
} else if (hr == S_FALSE) { } else if (hr == S_FALSE) {
// This is not an error. We are allowed to call CoInitializeEx more than // This is not an error. We are allowed to call CoInitializeEx more than
// once, as long as it is matches by an CoUninitialize call. // once, as long as it is matches by an CoUninitialize call.
// We do that in the dtor which is guaranteed to be called. // We do that in the dtor which is guaranteed to be called.
LOG("COM already initialized in MTA"); LOG("COM already initialized in MTA");
need_uninit = true;
} else if (hr == S_OK) { } else if (hr == S_OK) {
LOG("COM initialized."); LOG("COM initialized.");
need_uninit = true;
} }
} }
~auto_com() { ~auto_com() {