Bug 1657205 - Fallibly allocate for StartupCache from Omnijar r=froydnj

This changes the StartupCache::PutBuffer call from Omnijar to use a
fallibly allocated buffer, to reduce OOM crashes. We can/should broaden the
scope of this, but this is a simple initial change to mitigate the OOM
crashed introduced with bug 1627075.

Differential Revision: https://phabricator.services.mozilla.com/D86067
This commit is contained in:
Doug Thayer 2020-08-07 20:05:59 +00:00
Родитель 914ea37ede
Коммит 4e1e2e3037
1 изменённых файлов: 8 добавлений и 5 удалений

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

@ -14,6 +14,7 @@
#include "nsNetUtil.h"
#include "mozilla/scache/StartupCache.h"
#include "mozilla/MmapFaultHandler.h"
#include "mozilla/UniquePtrExtensions.h"
namespace mozilla {
@ -438,12 +439,14 @@ void CacheAwareZipReader::PutBufferIntoCache(const nsCString& aCacheKey,
}
auto* cache = scache::StartupCache::GetSingleton();
auto dataCopy = MakeUnique<char[]>(aSize);
auto dataCopy = MakeUniqueFallible<char[]>(aSize);
MMAP_FAULT_HANDLER_BEGIN_BUFFER(aBuffer, aSize)
memcpy(dataCopy.get(), aBuffer, aSize);
MMAP_FAULT_HANDLER_CATCH()
Unused << cache->PutBuffer(aCacheKey.get(), std::move(dataCopy), aSize);
if (dataCopy) {
MMAP_FAULT_HANDLER_BEGIN_BUFFER(aBuffer, aSize)
memcpy(dataCopy.get(), aBuffer, aSize);
MMAP_FAULT_HANDLER_CATCH()
Unused << cache->PutBuffer(aCacheKey.get(), std::move(dataCopy), aSize);
}
}
void CacheAwareZipReader::PushSuspendStartupCacheWrites() {