Skip to content

Commit

Permalink
Fix incorrect use of GetProcessMemoryInfo's return value. (#1315)
Browse files Browse the repository at this point in the history
Summary:
According to the API documentation [GetProcessMemoryInfo function (psapi.h)
](https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getprocessmemoryinfo)

> If the function succeeds, the return value is nonzero.
> If the function fails, the return value is zero. To get extended error information, call [GetLastError](https://learn.microsoft.com/en-us/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror).

Pull Request resolved: #1315

Test Plan:
- Turn on ShouldRecordStats ( GCConfig.h )
- Be able to get the actual value instead of 0

Reviewed By: neildhar

Differential Revision: D53901267

Pulled By: tmikov

fbshipit-source-id: 9053e0e94eddee30a9bcf6b50e32bd01a0172eb5
  • Loading branch information
mylhyz authored and facebook-github-bot committed Feb 19, 2024
1 parent e7f86e3 commit 5f28c30
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Support/OSCompatWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ int pages_in_ram(const void *p, size_t sz, llvh::SmallVectorImpl<int> *runs) {

uint64_t peak_rss() {
PROCESS_MEMORY_COUNTERS pmc;
auto ret = GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
if (ret != 0) {
BOOL ret = GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
if (!ret) {
// failed
return 0;
}
Expand All @@ -365,8 +365,8 @@ uint64_t peak_rss() {

uint64_t current_rss() {
PROCESS_MEMORY_COUNTERS pmc;
auto ret = GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
if (ret != 0) {
BOOL ret = GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
if (!ret) {
// failed
return 0;
}
Expand Down

0 comments on commit 5f28c30

Please sign in to comment.