Windows CoUninitialize() should only be called if CoInitializeEx() succeeded
btzy opened this issue · comments
Bernard Teo commented
Lines 369-373 of nfd_win.cpp (using devel branch):
if ( !SUCCEEDED(result))
{
NFDi_SetError("Could not initialize COM.");
goto end;
}
In the existing implementation, the above code is executed when CoInitializeEx() fails. end
is where CoUninitialize() is called. Calling CoUninitialize() if CoInitializeEx() fails is wrong, according to the MSDN documentation:
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.
So we shouldn't be calling CoUninitialize() if it CoInitializeEx() does not succeed.
Michael Labbe commented
Fixed in f055c30.