Bug 1804499 - [1/4] Handle Windows error code consistently r=glandium

The real ::VirtualAlloc does not modify the existing last-error code in
case of success; therefore, neither should we.

Differential Revision: https://phabricator.services.mozilla.com/D164105
This commit is contained in:
Ray Kraesig 2023-01-19 16:16:41 +00:00
parent 2e0b78ffc1
commit a27f258c20

View File

@ -1517,6 +1517,8 @@ static inline StallSpecs GetStallSpecs() {
// Ref: https://docs.microsoft.com/en-us/troubleshoot/windows-client/performance/slow-page-file-growth-memory-allocation-errors
[[nodiscard]] void* MozVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize,
DWORD flAllocationType, DWORD flProtect) {
DWORD const lastError = ::GetLastError();
constexpr auto IsOOMError = [] {
switch (::GetLastError()) {
// This is the usual error result from VirtualAlloc for OOM.
@ -1553,7 +1555,7 @@ static inline StallSpecs GetStallSpecs() {
// The OOM status has been handled, and should not be reported to
// telemetry.
if (IsOOMError()) {
::SetLastError(0);
::SetLastError(lastError);
}
return ptr;
}