From e4e80c5463baea8d8881f927da3002f03ef67cfd Mon Sep 17 00:00:00 2001 From: X-BW <45979878+Whitecx@users.noreply.github.com> Date: Fri, 9 May 2025 15:41:23 -0400 Subject: [PATCH] src: fix module buffer allocation PR-URL: https://github.com/nodejs/node/pull/57738 Reviewed-By: Anna Henningsen --- src/debug_utils.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/debug_utils.cc b/src/debug_utils.cc index 8a85e066fd9..97884b9a0f8 100644 --- a/src/debug_utils.cc +++ b/src/debug_utils.cc @@ -471,7 +471,7 @@ std::vector NativeSymbolDebuggingContext::GetLoadedLibraries() { DWORD size_2 = 0; // First call to get the size of module array needed if (EnumProcessModules(process_handle, nullptr, 0, &size_1)) { - MallocedBuffer modules(size_1); + MallocedBuffer modules(size_1 / sizeof(HMODULE)); // Second call to populate the module array if (EnumProcessModules(process_handle, modules.data, size_1, &size_2)) { @@ -480,16 +480,15 @@ std::vector NativeSymbolDebuggingContext::GetLoadedLibraries() { i++) { WCHAR module_name[MAX_PATH]; // Obtain and report the full pathname for each module - if (GetModuleFileNameExW(process_handle, - modules.data[i], - module_name, - arraysize(module_name) / sizeof(WCHAR))) { + if (GetModuleFileNameW( + modules.data[i], module_name, arraysize(module_name))) { DWORD size = WideCharToMultiByte( CP_UTF8, 0, module_name, -1, nullptr, 0, nullptr, nullptr); char* str = new char[size]; WideCharToMultiByte( CP_UTF8, 0, module_name, -1, str, size, nullptr, nullptr); list.emplace_back(str); + delete str; } } }