mlabbe / nativefiledialog

A tiny, neat C library that portably invokes native file open and save dialogs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Windows CoUninitialize() should only be called if CoInitializeEx() succeeded

btzy opened this issue · comments

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.

Fixed in f055c30.