diff --git a/src/node_internals.h b/src/node_internals.h index 5604f35aeff6b4..c9d6881cb8fbbf 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -192,16 +192,13 @@ 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; }