Call CoUninitialize, if CoInitializeEx was successful.#15
Call CoUninitialize, if CoInitializeEx was successful.#15amodm merged 2 commits intoamodm:masterfrom
Conversation
|
Thanks for the contribution, @hrydgard. I'm not very familiar with the Windows API, so can you help me understand if there are any implications stemming from the following API documentation?
|
|
Every successful CoInitialize must be matched with a CoUninitialize, otherwise the reference count will be out of whack and COM will never be unloaded even when it's possible and desired. If an application was already using COM for something, their reference count was already 1 or more. Adding a CoUninitialize call like this will not break anything, it will only make sure that we don't "leak" reference count, like this library currently does. |
|
So, if I'm understanding this correctly, our |
|
Yeah, pretty much. If we succeeded, we incremented the reference count and should decrement it. If we failed, a caller had already called CoInitialize with a different threading mode, and we should not decrement the count. Fortunately ShellExecute works in either threading mode so it doesn't matter for us if we failed or succeeded, we just need to do the right thing when leaving. |
|
Released under 0.5.2 |
From https://docs.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializeex :
"To close the COM library gracefully on a thread, each successful call to CoInitialize or CoInitializeEx, including any call that returns S_FALSE, must be balanced by a corresponding call to CoUninitialize.".