Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Slab allocator: don't attempt to shrink a non-buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Apr 11, 2012
1 parent 9b7a6c5 commit 3ec84a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/slab_allocator.cc
Expand Up @@ -116,7 +116,8 @@ Local<Object> SlabAllocator::Shrink(Handle<Object> obj,
assert(!slab_v.IsEmpty());
assert(slab_v->IsObject());
Local<Object> slab = slab_v->ToObject();
if (ptr && ptr == last_ptr_) {
assert(ptr != NULL);
if (ptr == last_ptr_) {
last_ptr_ = NULL;
offset_ = ptr - Buffer::Data(slab) + ROUND_UP(size, 16);
}
Expand Down
15 changes: 11 additions & 4 deletions src/stream_wrap.cc
Expand Up @@ -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);

Expand Down

0 comments on commit 3ec84a1

Please sign in to comment.