From ea090e178614723cbd572d6b3ba644e7f23c1926 Mon Sep 17 00:00:00 2001 From: rglarix Date: Fri, 10 Mar 2017 16:23:12 +0100 Subject: [PATCH] fix: obtain ldrlock before dumping leaks, to avoid deadlocks when resolving callstack (e.g. GetModuleName) While dumping leaks, vld calls GetModuleName during callstack resolving, but this function takes ldrlock. If other threads call functions taking ldrlock and also triggering vld code (e.g. module unloading) this leads to a deadlock. Signed-off-by: rglarix --- src/vld.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vld.cpp b/src/vld.cpp index d19295ff..29b01958 100644 --- a/src/vld.cpp +++ b/src/vld.cpp @@ -2419,6 +2419,8 @@ SIZE_T VisualLeakDetector::ReportThreadLeaks( DWORD threadId ) return 0; } + LoaderLock ll; // scanning for module names needs ldrloc - getting it proactively to avoid deadlocks later + // Generate a memory leak report for each heap in the process. SIZE_T leaksCount = 0; CriticalSectionLocker<> cs(g_heapMapLock);