Fix bogus calls to GetMemoryStatus and GetMemoryStatusEx: need to set the dwLength member of the struct prior to calling. Otherwise it's just a garbage value from the stack. Also, pay attention to return value of GetMemoryStatusEx: if it indicates failure then just return 0 without using any of the other data the call returns.

This commit is contained in:
David Cole 2009-11-18 11:22:38 -05:00
parent 5fbefd66dc
commit ba21622048
1 changed files with 6 additions and 1 deletions

View File

@ -2279,11 +2279,16 @@ int SystemInformationImplementation::QueryMemory()
#elif _WIN32
#if _MSC_VER < 1300
MEMORYSTATUS ms;
ms.dwLength = sizeof(ms);
GlobalMemoryStatus(&ms);
#define MEM_VAL(value) dw##value
#else
MEMORYSTATUSEX ms;
GlobalMemoryStatusEx(&ms);
ms.dwLength = sizeof(ms);
if (0 == GlobalMemoryStatusEx(&ms))
{
return 0;
}
#define MEM_VAL(value) ull##value
#endif
unsigned long tv = ms.MEM_VAL(TotalVirtual);