diff --git a/src/node_internals.h b/src/node_internals.h index 9a96e042fc5cda..f89b60a4a8835a 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -190,16 +190,12 @@ static v8::MaybeLocal New(Environment* env, char* src = reinterpret_cast(buf->out()); const size_t len_in_bytes = buf->length() * sizeof(buf->out()[0]); - if (buf->IsAllocated()) + if (buf->IsAllocated()) { ret = New(env, src, len_in_bytes); - else if (!buf->IsInvalidated()) - ret = Copy(env, src, len_in_bytes); - - if (ret.IsEmpty()) - return ret; - - if (buf->IsAllocated()) + // new always takes ownership of src buf->Release(); + } else if (!buf->IsInvalidated()) + ret = Copy(env, src, len_in_bytes); return ret; }