Add missing CloseHandle()

This commit is contained in:
firesgc 2025-01-25 11:48:35 +01:00
parent 7728e7834b
commit 70089f3522
3 changed files with 18 additions and 4 deletions

View File

@ -23,6 +23,9 @@ namespace detail {
if(!SymCleanup(kvp.second)) { if(!SymCleanup(kvp.second)) {
ASSERT(false, microfmt::format("Cpptrace SymCleanup failed with code {}\n", GetLastError()).c_str()); 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());
}
} }
} }

View File

@ -426,17 +426,22 @@ namespace dbghelp {
// TODO: When does this need to be called? Can it be moved to the symbolizer? // TODO: When does this need to be called? Can it be moved to the symbolizer?
SymSetOptions(SYMOPT_ALLOW_ABSOLUTE_SYMBOLS); SymSetOptions(SYMOPT_ALLOW_ABSOLUTE_SYMBOLS);
HANDLE duplicatedHandle = nullptr;
HANDLE proc = GetCurrentProcess(); HANDLE proc = GetCurrentProcess();
if(get_cache_mode() == cache_mode::prioritize_speed) { if(get_cache_mode() == cache_mode::prioritize_speed) {
get_syminit_manager().init(proc); duplicatedHandle = get_syminit_manager().init(proc);
} else { } 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"); throw internal_error("SymInitialize failed");
} }
} }
for(const auto frame : frames) { for(const auto frame : frames) {
try { try {
trace.push_back(resolve_frame(proc, frame)); trace.push_back(resolve_frame(duplicatedHandle, frame));
} catch(...) { // NOSONAR } catch(...) { // NOSONAR
if(!detail::should_absorb_trace_exceptions()) { if(!detail::should_absorb_trace_exceptions()) {
throw; throw;
@ -447,9 +452,12 @@ namespace dbghelp {
} }
} }
if(get_cache_mode() != cache_mode::prioritize_speed) { if(get_cache_mode() != cache_mode::prioritize_speed) {
if(!SymCleanup(proc)) { if(!SymCleanup(duplicatedHandle)) {
throw internal_error("SymCleanup failed"); throw internal_error("SymCleanup failed");
} }
if (!CloseHandle(duplicatedHandle)) {
throw internal_error("CloseHandle failed");
}
} }
return trace; return trace;
} }

View File

@ -152,6 +152,9 @@ namespace detail {
if(!SymCleanup(duplicatedHandle)) { if(!SymCleanup(duplicatedHandle)) {
throw internal_error("SymCleanup failed"); throw internal_error("SymCleanup failed");
} }
if (!CloseHandle(duplicatedHandle)) {
throw internal_error("CloseHandle failed");
}
} }
return trace; return trace;
} }