diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-10 18:51:34 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-10 18:51:34 +0000 |
commit | 776e175577badb594cc9023f56b16480546c94ea (patch) | |
tree | d4159651d2165dd6bbfbdae51faa4ac77404f870 /net | |
parent | 62cf690a77564be902cf481803a9a7e3d52f7c55 (diff) | |
download | chromium_src-776e175577badb594cc9023f56b16480546c94ea.zip chromium_src-776e175577badb594cc9023f56b16480546c94ea.tar.gz chromium_src-776e175577badb594cc9023f56b16480546c94ea.tar.bz2 |
After further discussion, do not try to handle memory errors, but make assertions about allocation parameters stronger.
BUG=25826
TEST=none
Review URL: http://codereview.chromium.org/378037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31574 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/io_buffer.cc | 15 | ||||
-rw-r--r-- | net/base/io_buffer.h | 5 | ||||
-rw-r--r-- | net/http/http_stream_parser.cc | 18 | ||||
-rw-r--r-- | net/websockets/websocket_throttle.cc | 12 |
4 files changed, 15 insertions, 35 deletions
diff --git a/net/base/io_buffer.cc b/net/base/io_buffer.cc index 9ae2746..4aa469a 100644 --- a/net/base/io_buffer.cc +++ b/net/base/io_buffer.cc @@ -19,20 +19,17 @@ void DrainableIOBuffer::SetOffset(int bytes) { data_ = base_->data() + used_; } -bool GrowableIOBuffer::SetCapacity(int capacity) { - DCHECK_GE(capacity, 0); - 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; - } +void GrowableIOBuffer::SetCapacity(int capacity) { + CHECK(capacity >= 0); + // realloc will crash if it fails. + real_data_.reset(static_cast<char*>(realloc(real_data_.release(), capacity))); + // Sanity check. + CHECK(real_data_.get() != NULL || capacity == 0); capacity_ = capacity; if (offset_ > capacity) set_offset(capacity); else set_offset(offset_); // The pointer may have changed. - return true; } void GrowableIOBuffer::set_offset(int offset) { diff --git a/net/base/io_buffer.h b/net/base/io_buffer.h index adcf698..671b263 100644 --- a/net/base/io_buffer.h +++ b/net/base/io_buffer.h @@ -112,9 +112,8 @@ class GrowableIOBuffer : public IOBuffer { public: GrowableIOBuffer() : IOBuffer(), capacity_(0), offset_(0) {} - // realloc memory to the specified capacity. Returns true on success. - // On failure, the capacity and buffer are unchanged. - bool SetCapacity(int capacity); + // realloc memory to the specified capacity. + void SetCapacity(int capacity); int capacity() { return capacity_; } // |offset| moves the |data_| pointer, allowing "seeking" in the data. diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc index b5394d7..ddf7663 100644 --- a/net/http/http_stream_parser.cc +++ b/net/http/http_stream_parser.cc @@ -208,10 +208,8 @@ int HttpStreamParser::DoReadHeaders() { io_state_ = STATE_READ_HEADERS_COMPLETE; // Grow the read buffer if necessary. - if (read_buf_->RemainingCapacity() == 0) { - if (!read_buf_->SetCapacity(read_buf_->capacity() + kHeaderBufInitialSize)) - return ERR_OUT_OF_MEMORY; - } + if (read_buf_->RemainingCapacity() == 0) + read_buf_->SetCapacity(read_buf_->capacity() + kHeaderBufInitialSize); // http://crbug.com/16371: We're seeing |user_buf_->data()| return NULL. // See if the user is passing in an IOBuffer with a NULL |data_|. @@ -302,7 +300,6 @@ int HttpStreamParser::DoReadHeadersComplete(int result) { read_buf_->StartOfBuffer() + read_buf_unused_offset_, extra_bytes); } - // Ok if this fails, since it only shrinks the buffer. read_buf_->SetCapacity(extra_bytes); read_buf_unused_offset_ = 0; return OK; @@ -386,16 +383,11 @@ int HttpStreamParser::DoReadBodyComplete(int result) { if (result > 0) result -= save_amount; } + if (read_buf_->capacity() < save_amount + additional_save_amount) { - if (!read_buf_->SetCapacity(save_amount + additional_save_amount)) { - // This response is ok, but we weren't able to copy the extra data, - // so close the connection so that it is not reused. - connection_->socket()->Disconnect(); - connection_->Reset(); - read_buf_unused_offset_ = -1; // So that IsMoreDataBuffered works. - return result; - } + read_buf_->SetCapacity(save_amount + additional_save_amount); } + if (save_amount) { memcpy(read_buf_->StartOfBuffer(), user_read_buf_->data() + result, save_amount); diff --git a/net/websockets/websocket_throttle.cc b/net/websockets/websocket_throttle.cc index 49bd923..db41248 100644 --- a/net/websockets/websocket_throttle.cc +++ b/net/websockets/websocket_throttle.cc @@ -85,16 +85,8 @@ class WebSocketThrottle::WebSocketState : public SocketStream::UserData { } buffer_ = new GrowableIOBuffer(); buffer_->SetCapacity(kBufferSize); - } else { - if (buffer_->RemainingCapacity() < len) { - if (!buffer_->SetCapacity(buffer_->capacity() + kBufferSize)) { - // TODO(ukai): Check more correctly. - // Seek to the last CR or LF and reduce memory usage. - LOG(ERROR) << "Too large headers? capacity=" << buffer_->capacity(); - handshake_finished_ = true; - return OK; - } - } + } else if (buffer_->RemainingCapacity() < len) { + buffer_->SetCapacity(buffer_->capacity() + kBufferSize); } memcpy(buffer_->data(), data, len); buffer_->set_offset(buffer_->offset() + len); |