Replace OpenProcess with GetCurrentProcess where appropriate (#6914)
GetCurrentProcess is more correct and resolves spurious AV warnings.
This commit is contained in:
parent
d35183921b
commit
5c9bc26ed5
2 changed files with 9 additions and 17 deletions
|
@ -33,22 +33,20 @@ std::wstring BlacklistedLibraryCheck::get_blacklisted_string()
|
||||||
|
|
||||||
bool BlacklistedLibraryCheck::perform_check()
|
bool BlacklistedLibraryCheck::perform_check()
|
||||||
{
|
{
|
||||||
// Get a handle to the process.
|
// Get the pseudo-handle for the current process.
|
||||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId());
|
HANDLE hCurrentProcess = GetCurrentProcess();
|
||||||
if (NULL == hProcess)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Get a list of all the modules in this process.
|
// Get a list of all the modules in this process.
|
||||||
HMODULE hMods[1024];
|
HMODULE hMods[1024];
|
||||||
DWORD cbNeeded;
|
DWORD cbNeeded;
|
||||||
if (EnumProcessModulesEx(hProcess, hMods, sizeof(hMods), &cbNeeded, LIST_MODULES_ALL))
|
if (EnumProcessModulesEx(hCurrentProcess, hMods, sizeof(hMods), &cbNeeded, LIST_MODULES_ALL))
|
||||||
{
|
{
|
||||||
//printf("Total Dlls: %d\n", cbNeeded / sizeof(HMODULE));
|
//printf("Total Dlls: %d\n", cbNeeded / sizeof(HMODULE));
|
||||||
for (unsigned int i = 0; i < cbNeeded / sizeof(HMODULE); ++ i)
|
for (unsigned int i = 0; i < cbNeeded / sizeof(HMODULE); ++ i)
|
||||||
{
|
{
|
||||||
wchar_t szModName[MAX_PATH];
|
wchar_t szModName[MAX_PATH];
|
||||||
// Get the full path to the module's file.
|
// Get the full path to the module's file.
|
||||||
if (GetModuleFileNameExW(hProcess, hMods[i], szModName, MAX_PATH))
|
if (GetModuleFileNameExW(hCurrentProcess, hMods[i], szModName, MAX_PATH))
|
||||||
{
|
{
|
||||||
// Add to list if blacklisted
|
// Add to list if blacklisted
|
||||||
if (BlacklistedLibraryCheck::is_blacklisted(szModName)) {
|
if (BlacklistedLibraryCheck::is_blacklisted(szModName)) {
|
||||||
|
@ -61,7 +59,6 @@ bool BlacklistedLibraryCheck::perform_check()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(hProcess);
|
|
||||||
//printf("\n");
|
//printf("\n");
|
||||||
return !m_found.empty();
|
return !m_found.empty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -984,16 +984,11 @@ std::string log_memory_info(bool ignore_loglevel)
|
||||||
} PROCESS_MEMORY_COUNTERS_EX, *PPROCESS_MEMORY_COUNTERS_EX;
|
} PROCESS_MEMORY_COUNTERS_EX, *PPROCESS_MEMORY_COUNTERS_EX;
|
||||||
#endif /* PROCESS_MEMORY_COUNTERS_EX */
|
#endif /* PROCESS_MEMORY_COUNTERS_EX */
|
||||||
|
|
||||||
|
PROCESS_MEMORY_COUNTERS_EX pmc;
|
||||||
HANDLE hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ::GetCurrentProcessId());
|
if (GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)))
|
||||||
if (hProcess != nullptr) {
|
out = " WorkingSet: " + format_memsize_MB(pmc.WorkingSetSize) + "; PrivateBytes: " + format_memsize_MB(pmc.PrivateUsage) + "; Pagefile(peak): " + format_memsize_MB(pmc.PagefileUsage) + "(" + format_memsize_MB(pmc.PeakPagefileUsage) + ")";
|
||||||
PROCESS_MEMORY_COUNTERS_EX pmc;
|
else
|
||||||
if (GetProcessMemoryInfo(hProcess, (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)))
|
out += " Used memory: N/A";
|
||||||
out = " WorkingSet: " + format_memsize_MB(pmc.WorkingSetSize) + "; PrivateBytes: " + format_memsize_MB(pmc.PrivateUsage) + "; Pagefile(peak): " + format_memsize_MB(pmc.PagefileUsage) + "(" + format_memsize_MB(pmc.PeakPagefileUsage) + ")";
|
|
||||||
else
|
|
||||||
out += " Used memory: N/A";
|
|
||||||
CloseHandle(hProcess);
|
|
||||||
}
|
|
||||||
#elif defined(__linux__) or defined(__APPLE__)
|
#elif defined(__linux__) or defined(__APPLE__)
|
||||||
// Get current memory usage.
|
// Get current memory usage.
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
Loading…
Add table
Reference in a new issue