diff --git a/src/platform/dbghelp_syminit_manager.cpp b/src/platform/dbghelp_syminit_manager.cpp index 6904b16..1dc635a 100644 --- a/src/platform/dbghelp_syminit_manager.cpp +++ b/src/platform/dbghelp_syminit_manager.cpp @@ -23,6 +23,9 @@ namespace detail { if(!SymCleanup(kvp.second)) { ASSERT(false, microfmt::format("Cpptrace SymCleanup failed with code {}\n", GetLastError()).c_str()); } + if (!CloseHandle(kvp.second)) { + ASSERT(false, microfmt::format("Cpptrace CloseHandle failed with code {}\n", GetLastError()).c_str()); + } } } diff --git a/src/symbols/symbols_with_dbghelp.cpp b/src/symbols/symbols_with_dbghelp.cpp index 0e665a9..94eb3a3 100644 --- a/src/symbols/symbols_with_dbghelp.cpp +++ b/src/symbols/symbols_with_dbghelp.cpp @@ -426,17 +426,22 @@ namespace dbghelp { // TODO: When does this need to be called? Can it be moved to the symbolizer? SymSetOptions(SYMOPT_ALLOW_ABSOLUTE_SYMBOLS); + + HANDLE duplicatedHandle = nullptr; HANDLE proc = GetCurrentProcess(); if(get_cache_mode() == cache_mode::prioritize_speed) { - get_syminit_manager().init(proc); + duplicatedHandle = get_syminit_manager().init(proc); } else { - if(!SymInitialize(proc, NULL, TRUE)) { + if (!DuplicateHandle(proc, proc, proc, &duplicatedHandle, 0, FALSE, DUPLICATE_SAME_ACCESS)) { + throw internal_error("DuplicateHandle failed"); + } + if(!SymInitialize(duplicatedHandle, NULL, TRUE)) { throw internal_error("SymInitialize failed"); } } for(const auto frame : frames) { try { - trace.push_back(resolve_frame(proc, frame)); + trace.push_back(resolve_frame(duplicatedHandle, frame)); } catch(...) { // NOSONAR if(!detail::should_absorb_trace_exceptions()) { throw; @@ -447,9 +452,12 @@ namespace dbghelp { } } if(get_cache_mode() != cache_mode::prioritize_speed) { - if(!SymCleanup(proc)) { + if(!SymCleanup(duplicatedHandle)) { throw internal_error("SymCleanup failed"); } + if (!CloseHandle(duplicatedHandle)) { + throw internal_error("CloseHandle failed"); + } } return trace; } diff --git a/src/unwind/unwind_with_dbghelp.cpp b/src/unwind/unwind_with_dbghelp.cpp index 64e530d..949d796 100644 --- a/src/unwind/unwind_with_dbghelp.cpp +++ b/src/unwind/unwind_with_dbghelp.cpp @@ -152,6 +152,9 @@ namespace detail { if(!SymCleanup(duplicatedHandle)) { throw internal_error("SymCleanup failed"); } + if (!CloseHandle(duplicatedHandle)) { + throw internal_error("CloseHandle failed"); + } } return trace; }