Bug 1863120 - SharedMemory::FindFreeAddressSpace performs incorrect munmap on allocation failure. r=jld.

SharedMemory::FindFreeAddressSpace will bogusly try to do `munmap(MAP_FAILED, size)`
if the preceding `mmap` fails.  This patch guards the `munmap` with a failure check.

Differential Revision: https://phabricator.services.mozilla.com/D192799
This commit is contained in:
Julian Seward 2023-11-07 07:46:09 +00:00
Родитель 7cc44b55a0
Коммит 3c2f4aaaa5
1 изменённых файлов: 4 добавлений и 1 удалений

Просмотреть файл

@ -529,8 +529,11 @@ bool SharedMemory::Map(size_t bytes, void* fixed_address) {
void* SharedMemory::FindFreeAddressSpace(size_t size) {
void* memory = mmap(nullptr, size, PROT_NONE,
MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE, -1, 0);
if (memory == MAP_FAILED) {
return nullptr;
}
munmap(memory, size);
return memory != MAP_FAILED ? memory : NULL;
return memory;
}
SharedMemoryHandle SharedMemory::CloneHandle() {