Commit 1d6745b2 authored by Benoît Lizé's avatar Benoît Lizé Committed by Commit Bot

zlib/google: Use UncheckedMalloc() to allocate memory instead of malloc().

On Windows, malloc() (in Chrome) never returns nullptr, instead triggering an
OOM. Explicitly using UncheckedMalloc() to get nullptr in case of allocation
failure.

Bug: 905777
Change-Id: I56bf677710b606cc6ca69073f4cc2d34c4ef19dd
Reviewed-on: https://chromium-review.googlesource.com/c/1344064Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609991}
parent 89540506
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/bit_cast.h" #include "base/bit_cast.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/process/memory.h"
#include "base/sys_byteorder.h" #include "base/sys_byteorder.h"
#if defined(USE_SYSTEM_ZLIB) #if defined(USE_SYSTEM_ZLIB)
...@@ -130,10 +131,11 @@ bool GzipCompress(base::StringPiece input, std::string* output) { ...@@ -130,10 +131,11 @@ bool GzipCompress(base::StringPiece input, std::string* output) {
uLongf compressed_data_size = uLongf compressed_data_size =
kGzipZlibHeaderDifferenceBytes + compressBound(input_size); kGzipZlibHeaderDifferenceBytes + compressBound(input_size);
Bytef* compressed_data = Bytef* compressed_data;
reinterpret_cast<Bytef*>(malloc(compressed_data_size)); if (!base::UncheckedMalloc(compressed_data_size,
if (!compressed_data) reinterpret_cast<void**>(&compressed_data))) {
return false; return false;
}
if (GzipCompressHelper(compressed_data, &compressed_data_size, if (GzipCompressHelper(compressed_data, &compressed_data_size,
bit_cast<const Bytef*>(input.data()), bit_cast<const Bytef*>(input.data()),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment