Skip to content

Commit 962b1cf

Browse files
committed
Fix infinite loop with LogPrint on Windows
Running -printtodebugger -debug (or -debug=lock), compiled with -DDEBUG_LOCKORDER would infinite loop on Windows because every critical section lock/unlock triggers a LogPrint. Solution is to use the raw boost mutex instead of a CCriticalSection.
1 parent 955787f commit 962b1cf

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/util.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -299,27 +299,24 @@ int LogPrint(const char* category, const char* pszFormat, ...)
299299
#ifdef WIN32
300300
if (fPrintToDebugger)
301301
{
302-
static CCriticalSection cs_OutputDebugStringF;
303-
304302
// accumulate and output a line at a time
305-
{
306-
LOCK(cs_OutputDebugStringF);
307-
static std::string buffer;
303+
static std::string buffer;
308304

309-
va_list arg_ptr;
310-
va_start(arg_ptr, pszFormat);
311-
buffer += vstrprintf(pszFormat, arg_ptr);
312-
va_end(arg_ptr);
305+
boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
313306

314-
int line_start = 0, line_end;
315-
while((line_end = buffer.find('\n', line_start)) != -1)
316-
{
317-
OutputDebugStringA(buffer.substr(line_start, line_end - line_start).c_str());
318-
line_start = line_end + 1;
319-
ret += line_end-line_start;
320-
}
321-
buffer.erase(0, line_start);
307+
va_list arg_ptr;
308+
va_start(arg_ptr, pszFormat);
309+
buffer += vstrprintf(pszFormat, arg_ptr);
310+
va_end(arg_ptr);
311+
312+
int line_start = 0, line_end;
313+
while((line_end = buffer.find('\n', line_start)) != -1)
314+
{
315+
OutputDebugStringA(buffer.substr(line_start, line_end - line_start).c_str());
316+
line_start = line_end + 1;
317+
ret += line_end-line_start;
322318
}
319+
buffer.erase(0, line_start);
323320
}
324321
#endif
325322
return ret;

0 commit comments

Comments
 (0)