diff --git a/src/assert.cpp b/src/assert.cpp index 3a07308b6..c4832aa3a 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -147,6 +147,7 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*) #include "windows.h" #include "libtorrent/utf8.hpp" +#include #include "winbase.h" #include "dbghelp.h" @@ -154,6 +155,11 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*) TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth , void* ctx) { + // all calls to DbgHlp.dll are thread-unsafe. i.e. they all need to be + // synchronized and not called concurrently. This mutex serializes access + static std::mutex dbghlp_mutex; + std::lock_guard l(dbghlp_mutex); + CONTEXT context_record; if (ctx) { diff --git a/test/main.cpp b/test/main.cpp index 6596836d9..8d796bc86 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -52,6 +52,7 @@ POSSIBILITY OF SUCH DAMAGE. #include // fot SetErrorMode #include // for _dup and _dup2 #include // for _getpid +#include #define dup _dup #define dup2 _dup2 @@ -279,6 +280,11 @@ EXPORT int main(int argc, char const* argv[]) SetUnhandledExceptionFilter(&seh_exception_handler); +#ifdef _DEBUG + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); +#endif + #else signal(SIGSEGV, &sig_handler);