diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-28 00:01:33 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-28 00:01:33 +0000 |
commit | 28658b28eea506af35897723adb7c69e67327351 (patch) | |
tree | 9810112b06a9e97066d652a1c384c68e7c885cf4 /net/base/io_buffer.cc | |
parent | 403c148688f2c23d2c9b56fff236f4ddfe03377c (diff) | |
download | chromium_src-28658b28eea506af35897723adb7c69e67327351.zip chromium_src-28658b28eea506af35897723adb7c69e67327351.tar.gz chromium_src-28658b28eea506af35897723adb7c69e67327351.tar.bz2 |
Handle out of memory in GrowableIOBuffer more gracefully.
BUG=25826
TEST=none
Review URL: http://codereview.chromium.org/338049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30287 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/io_buffer.cc')
-rw-r--r-- | net/base/io_buffer.cc | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/net/base/io_buffer.cc b/net/base/io_buffer.cc index d348f37..9ae2746 100644 --- a/net/base/io_buffer.cc +++ b/net/base/io_buffer.cc @@ -19,15 +19,20 @@ void DrainableIOBuffer::SetOffset(int bytes) { data_ = base_->data() + used_; } -void GrowableIOBuffer::set_capacity(int capacity) { +bool GrowableIOBuffer::SetCapacity(int capacity) { DCHECK_GE(capacity, 0); - real_data_.reset(static_cast<char*>(realloc(real_data_.release(), capacity))); + char* cur_buf = real_data_.release(); + real_data_.reset(static_cast<char*>(realloc(cur_buf, capacity))); + if (real_data_.get() == NULL && capacity != 0) { + real_data_.reset(cur_buf); + return false; + } capacity_ = capacity; - CHECK(real_data_.get() != NULL || capacity == 0); if (offset_ > capacity) set_offset(capacity); else set_offset(offset_); // The pointer may have changed. + return true; } void GrowableIOBuffer::set_offset(int offset) { |