The Windows Embedded CE 6.0 R3 AppVerifier tool may report a memory leak in CoInitializeEx


Consider this scenario:
  • You are using the AppVerifier tool with the Heap Verifier (Shim_heap.dll) shim to test for memory leaks in your application.
  • The application you are testing calls CoInitializeEx to initialize the Component Object Model (COM).
  • Although your application calls CoUninitialize to close the COM library and free any resources that it maintains the AppVerifier tool reports one un-freed item and ole32.dll!CoInitializeEx is on the call stack of that report.


The problem is caused by the design of the ole32.dll DLL_PROCESS_DETACH handling in Windows Embedded CE 6.0 R3 which triggers a known false-positive memory leak being reported by AppVerifier. While processing DLL_PROCESS_DETACH a call to TlsFree is intentionally skipped because the kernel does automatically clean up the TLS slot shortly after the DllMain function in ole32.dll returns.


This AppVerifier false-positive can safely be ignored because the kernel does automatically clean up the relevant TLS slot.