summaryrefslogtreecommitdiffstats
path: root/net/http/http_stream_parser.cc
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-28 00:01:33 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-28 00:01:33 +0000
commit28658b28eea506af35897723adb7c69e67327351 (patch)
tree9810112b06a9e97066d652a1c384c68e7c885cf4 /net/http/http_stream_parser.cc
parent403c148688f2c23d2c9b56fff236f4ddfe03377c (diff)
downloadchromium_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/http/http_stream_parser.cc')
-rw-r--r--net/http/http_stream_parser.cc24
1 files changed, 17 insertions, 7 deletions
diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc
index e7c5146..b5394d7 100644
--- a/net/http/http_stream_parser.cc
+++ b/net/http/http_stream_parser.cc
@@ -208,8 +208,10 @@ int HttpStreamParser::DoReadHeaders() {
io_state_ = STATE_READ_HEADERS_COMPLETE;
// Grow the read buffer if necessary.
- if (read_buf_->RemainingCapacity() == 0)
- read_buf_->set_capacity(read_buf_->capacity() + kHeaderBufInitialSize);
+ if (read_buf_->RemainingCapacity() == 0) {
+ if (!read_buf_->SetCapacity(read_buf_->capacity() + kHeaderBufInitialSize))
+ return ERR_OUT_OF_MEMORY;
+ }
// 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_|.
@@ -300,7 +302,8 @@ int HttpStreamParser::DoReadHeadersComplete(int result) {
read_buf_->StartOfBuffer() + read_buf_unused_offset_,
extra_bytes);
}
- read_buf_->set_capacity(extra_bytes);
+ // Ok if this fails, since it only shrinks the buffer.
+ read_buf_->SetCapacity(extra_bytes);
read_buf_unused_offset_ = 0;
return OK;
}
@@ -324,12 +327,12 @@ int HttpStreamParser::DoReadBody() {
bytes_read);
read_buf_unused_offset_ += bytes_read;
if (bytes_read == available) {
- read_buf_->set_capacity(0);
+ read_buf_->SetCapacity(0);
read_buf_unused_offset_ = 0;
}
return bytes_read;
} else {
- read_buf_->set_capacity(0);
+ read_buf_->SetCapacity(0);
read_buf_unused_offset_ = 0;
}
}
@@ -384,11 +387,18 @@ int HttpStreamParser::DoReadBodyComplete(int result) {
result -= save_amount;
}
if (read_buf_->capacity() < save_amount + additional_save_amount) {
- read_buf_->set_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;
+ }
}
if (save_amount) {
memcpy(read_buf_->StartOfBuffer(), user_read_buf_->data() + result,
- save_amount);
+ save_amount);
read_buf_->set_offset(save_amount);
}
if (additional_save_amount) {