KindDragon / vld

Visual Leak Detector for Visual C++ 2008-2015
https://kinddragon.github.io/vld/
GNU Lesser General Public License v2.1
1.02k stars 314 forks source link

fix: obtain ldrlock before dumping leaks, to avoid deadlocks #29

Open rglarix opened 7 years ago

rglarix commented 7 years ago

While dumping leaks, vld calls GetModuleName during callstack resolving, but this function needs ldrlock.
If other threads call functions taking ldrlock and also triggering vld code (e.g. module unloading) this leads to a deadlock. The thread dumping leaks has g_heapMapLock and wants ldrlock, while the other has ldrlock (usually obtained directly by the windows method) and wants g_heapMapLock.

This patch fixes this situation by just taking ldrlock before doing a leak dump

KindDragon commented 7 years ago

@rglarix Thank you for all PR's. I will try to find time to review in the coming weeks. We also need to try fix build on AppVeyor

rglarix commented 7 years ago

Great, thank you. BTW, I've used vld to track a nasty memory increase bug in a complex multithreaded application. It worked like a charm, very useful indeed.