Bug 1778077 part 4 - Call WasmSharedArrayRawBuffer's destructor to ensure the mutex is destroyed. r=sfink

This fixes a pre-existing issue: `Mutex` has a destructor so we should call it.

Depends on D151010

Differential Revision: https://phabricator.services.mozilla.com/D151016
This commit is contained in:
Jan de Mooij 2022-07-07 07:28:27 +00:00
parent e83b79317b
commit 423773ff84
2 changed files with 9 additions and 2 deletions

View File

@ -26,6 +26,7 @@
# include <sys/mman.h>
#endif
#include <tuple> // std::tuple
#include <type_traits>
#ifdef MOZ_VALGRIND
# include <valgrind/memcheck.h>
#endif
@ -722,6 +723,9 @@ void WasmArrayRawBuffer::Release(void* mem) {
MOZ_RELEASE_ASSERT(header->mappedSize() <= SIZE_MAX - gc::SystemPageSize());
size_t mappedSizeWithHeader = header->mappedSize() + gc::SystemPageSize();
static_assert(std::is_trivially_destructible_v<WasmArrayRawBuffer>,
"no need to call the destructor");
UnmapBufferMemory(header->indexType(), header->basePointer(),
mappedSizeWithHeader);
}

View File

@ -204,10 +204,13 @@ void SharedArrayRawBuffer::dropReference() {
// This was the final reference, so release the buffer.
if (isWasm()) {
WasmSharedArrayRawBuffer* wasmBuf = toWasmBuffer();
wasm::IndexType indexType = wasmBuf->wasmIndexType();
uint8_t* basePointer = wasmBuf->basePointer();
size_t mappedSizeWithHeader =
wasmBuf->wasmMappedSize() + gc::SystemPageSize();
UnmapBufferMemory(wasmBuf->wasmIndexType(), wasmBuf->basePointer(),
mappedSizeWithHeader);
// Call the destructor to destroy the growLock_ Mutex.
wasmBuf->~WasmSharedArrayRawBuffer();
UnmapBufferMemory(indexType, basePointer, mappedSizeWithHeader);
} else {
js_delete(this);
}