Skip to content

Commit e9bf31e

Browse files
committed
src: fix double free reported by coverity
Fix double free reported by coverity. ToBufferEndian() in node_i18n.cc was the only caller of Buffer::New() passing in a MaybeStackBuffer. Coverity reported a double free because there were paths in which the src buffer would be deleted by both the destruction of the MaybeStackBuffer and by the Buffer which was done even in failure cases for Buffer::New(). Signed-off-by: Michael Dawson <[email protected]>
1 parent d4bcdd8 commit e9bf31e

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/node_internals.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,12 @@ static v8::MaybeLocal<v8::Object> New(Environment* env,
190190
char* src = reinterpret_cast<char*>(buf->out());
191191
const size_t len_in_bytes = buf->length() * sizeof(buf->out()[0]);
192192

193-
if (buf->IsAllocated())
193+
if (buf->IsAllocated()) {
194194
ret = New(env, src, len_in_bytes);
195-
else if (!buf->IsInvalidated())
196-
ret = Copy(env, src, len_in_bytes);
197-
198-
if (ret.IsEmpty())
199-
return ret;
200-
201-
if (buf->IsAllocated())
195+
// new always takes ownership of src
202196
buf->Release();
197+
} else if (!buf->IsInvalidated())
198+
ret = Copy(env, src, len_in_bytes);
203199

204200
return ret;
205201
}

0 commit comments

Comments
 (0)