How can I diagnose why my FreeLibrary isn’t freeing the library?
A customer had some code that called
FreeLibrary, and they expected the library to be freed, but it wasn’t happening. They suspect that there was an unmatched call to
LoadLibrary and was wondering if there were any diagnostic tools that would help them find it.
Application Verifier to the rescue.
Application Verifier maintains a history of module loads and unloads, and you can use the
!avrf -dlls debugger extension to view that log. For each module that is loaded and unloaded, it records a stack trace of the
The customer reported back that this debugger extension found the problem. Their code used the
DATA registry key to read some performance counters, and opening the performance counter was triggering an additional DLL load.