diff options
author | Bert Belder <bertbelder@gmail.com> | 2012-04-11 22:02:12 +0200 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2012-04-11 22:02:12 +0200 |
commit | 3ec84a11f8ce70bde3a480a80cbe0875f8ea08ae (patch) | |
tree | 3c1f916907cc1c1c2881da10f4b07faeac6d569c /src/stream_wrap.cc | |
parent | 9b7a6c523821f02ee85616160c56f7b6ffeddf7d (diff) | |
download | android-node-v8-3ec84a11f8ce70bde3a480a80cbe0875f8ea08ae.tar.gz android-node-v8-3ec84a11f8ce70bde3a480a80cbe0875f8ea08ae.tar.bz2 android-node-v8-3ec84a11f8ce70bde3a480a80cbe0875f8ea08ae.zip |
Slab allocator: don't attempt to shrink a non-buffer
Diffstat (limited to 'src/stream_wrap.cc')
-rw-r--r-- | src/stream_wrap.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 515fa9f41e..234aa3dc2f 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -162,16 +162,23 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread, // uv_close() on the handle. assert(wrap->object_.IsEmpty() == false); - Local<Object> slab = slab_allocator.Shrink(wrap->object_, - buf.base, - nread < 0 ? 0 : nread); - if (nread < 0) { + // If libuv reports an error or EOF it *may* give us a buffer back. In that + // case, return the space to the slab. + if (buf.base != NULL) { + slab_allocator.Shrink(wrap->object_, buf.base, 0); + } + SetErrno(uv_last_error(uv_default_loop())); MakeCallback(wrap->object_, "onread", 0, NULL); return; } + assert(buf.base != NULL); + Local<Object> slab = slab_allocator.Shrink(wrap->object_, + buf.base, + nread); + if (nread == 0) return; assert(static_cast<size_t>(nread) <= buf.len); |