Bug 902909 - Use fallible allocation when interfacing with Snappy. r=sicking,khuey (original patch by khuey, updated by janv)

This commit is contained in:
Kyle Huey 2013-08-12 13:27:53 -04:00
Родитель fcb9c82389
Коммит 59af5cdce4
2 изменённых файлов: 12 добавлений и 4 удалений

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

@ -55,6 +55,7 @@ using namespace mozilla::dom;
using namespace mozilla::dom::indexedDB::ipc;
using mozilla::dom::quota::FileOutputStream;
using mozilla::ErrorResult;
using mozilla::fallible_t;
BEGIN_INDEXEDDB_NAMESPACE
@ -1220,6 +1221,8 @@ IDBObjectStore::GetStructuredCloneReadInfoFromStatement(
const char* compressed = reinterpret_cast<const char*>(blobData);
size_t compressedLength = size_t(blobDataLength);
static const fallible_t fallible = fallible_t();
size_t uncompressedLength;
if (!snappy::GetUncompressedLength(compressed, compressedLength,
&uncompressedLength)) {
@ -1227,7 +1230,8 @@ IDBObjectStore::GetStructuredCloneReadInfoFromStatement(
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
nsAutoArrayPtr<char> uncompressed(new char[uncompressedLength]);
nsAutoArrayPtr<char> uncompressed(new (fallible) char[uncompressedLength]);
NS_ENSURE_TRUE(uncompressed, NS_ERROR_OUT_OF_MEMORY);
if (!snappy::RawUncompress(compressed, compressedLength,
uncompressed.get())) {
@ -1409,7 +1413,7 @@ StructuredCloneReadString(JSStructuredCloneReader* aReader,
}
length = SwapBytes(length);
if (!aString.SetLength(length, mozilla::fallible_t())) {
if (!aString.SetLength(length, fallible_t())) {
NS_WARNING("Out of memory?");
return false;
}
@ -3213,10 +3217,12 @@ AddHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
reinterpret_cast<const char*>(mCloneWriteInfo.mCloneBuffer.data());
size_t uncompressedLength = mCloneWriteInfo.mCloneBuffer.nbytes();
static const fallible_t fallible = fallible_t();
size_t compressedLength = snappy::MaxCompressedLength(uncompressedLength);
// This will hold our compressed data until the end of the method. The
// BindBlobByName function will copy it.
nsAutoArrayPtr<char> compressed(new char[compressedLength]);
nsAutoArrayPtr<char> compressed(new (fallible) char[compressedLength]);
NS_ENSURE_TRUE(compressed, NS_ERROR_OUT_OF_MEMORY);
snappy::RawCompress(uncompressed, uncompressedLength, compressed.get(),
&compressedLength);

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

@ -881,8 +881,10 @@ public:
rv = aArguments->GetSharedBlob(0, &uncompressedLength, &uncompressed);
NS_ENSURE_SUCCESS(rv, rv);
static const fallible_t fallible = fallible_t();
size_t compressedLength = snappy::MaxCompressedLength(uncompressedLength);
nsAutoArrayPtr<char> compressed(new char[compressedLength]);
nsAutoArrayPtr<char> compressed(new (fallible) char[compressedLength]);
NS_ENSURE_TRUE(compressed, NS_ERROR_OUT_OF_MEMORY);
snappy::RawCompress(reinterpret_cast<const char*>(uncompressed),
uncompressedLength, compressed.get(),