Browse Source

stream_wrap: fix memory leak on early return

v0.11.2-release
Brian White 12 years ago
committed by Ben Noordhuis
parent
commit
aca275f58d
  1. 6
      src/stream_wrap.cc

6
src/stream_wrap.cc

@ -538,9 +538,6 @@ Handle<Value> StreamWrap::Writev(const Arguments& args) {
uv_buf_t bufs_[16]; uv_buf_t bufs_[16];
uv_buf_t* bufs = bufs_; uv_buf_t* bufs = bufs_;
if (ARRAY_SIZE(bufs_) < count)
bufs = new uv_buf_t[count];
// Determine storage size first // Determine storage size first
size_t storage_size = 0; size_t storage_size = 0;
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
@ -578,6 +575,9 @@ Handle<Value> StreamWrap::Writev(const Arguments& args) {
return scope.Close(v8::Null(node_isolate)); return scope.Close(v8::Null(node_isolate));
} }
if (ARRAY_SIZE(bufs_) < count)
bufs = new uv_buf_t[count];
storage_size += sizeof(WriteWrap); storage_size += sizeof(WriteWrap);
char* storage = new char[storage_size]; char* storage = new char[storage_size];
WriteWrap* req_wrap = new (storage) WriteWrap(); WriteWrap* req_wrap = new (storage) WriteWrap();

Loading…
Cancel
Save