Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoInitialize/CoUninitialize will be unbalanced if app under single threaded COM #36

Open
ot32em opened this issue Oct 7, 2016 · 0 comments

Comments

@ot32em
Copy link

ot32em commented Oct 7, 2016

At the videoInput::comInit,
https://github.com/ofTheo/videoInput/blob/master/videoInputSrcAndDemos/libs/videoInput/videoInput.cpp#L1451

comUnInit() does not check whether the previous CoInitializeEx call in comInit() is failed or succeeded to call CoUninitialize. If the CoInitializeEx is failed because thread mode change, its internal reference count will not be added. Then still calling the CoUninitialize would cause the the CoInitialize/CoUninitialize unbalanced. Currently, it only send the warning as react.

See the remark of 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.

In my project (under single threaded com), I met a bug that my internal COM dll is always unloaded too early only on Windows 7 x86 (still don't know why it only happen on win7). I used the IInitializeSpy to monitor the changes of reference count of CoInitialize. I notices the reference count is always dropped by 1 if one of my module using opencv library was loaded by LoadLibrary.
Issue is gone after I unlink the highgui.dll from my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant