fix dbghlp heap corruption on windows

synchronize access to dbghlp.dll on windows
This commit is contained in:
Arvid Norberg 2016-07-25 08:05:26 -04:00 committed by GitHub
parent 118d06b780
commit 7fdab0d9e9
2 changed files with 12 additions and 0 deletions

View File

@ -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 <mutex>
#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<std::mutex> l(dbghlp_mutex);
CONTEXT context_record;
if (ctx)
{

View File

@ -52,6 +52,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <windows.h> // fot SetErrorMode
#include <io.h> // for _dup and _dup2
#include <process.h> // for _getpid
#include <crtdbg.h>
#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);