diff --git a/Source/JavaScriptCore/runtime/CachedTypes.cpp b/Source/JavaScriptCore/runtime/CachedTypes.cpp index aa6ab305398f..671df2e2fe21 100644 --- a/Source/JavaScriptCore/runtime/CachedTypes.cpp +++ b/Source/JavaScriptCore/runtime/CachedTypes.cpp @@ -721,7 +721,12 @@ class Encoder { } size_t size = m_baseOffset + m_currentPage->size(); - auto buffer = MallocSpan::malloc(size); + // The payload is the encoder's largest allocation and the cache is optional: report ENOMEM instead of crashing. + auto buffer = MallocSpan::tryMalloc(size); + if (!buffer) { + error = BytecodeCacheError::StandardError(ENOMEM); + return nullptr; + } auto bufferSpan = buffer.mutableSpan(); for (const auto& page : m_pages) memcpySpan(consumeSpan(bufferSpan, page.size()), page.span());