Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9b7f79a

Browse filesBrowse files
mhdawsonRafaelGSS
authored andcommitted
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 <midawson@redhat.com> PR-URL: #51046 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7f95926 commit 9b7f79a
Copy full SHA for 9b7f79a

File tree

Expand file treeCollapse file tree

1 file changed

+5
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-8
lines changed
Open diff view settings
Collapse file

‎src/node_internals.h‎

Copy file name to clipboardExpand all lines: src/node_internals.h
+5-8Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,13 @@ static v8::MaybeLocal<v8::Object> New(Environment* env,
192192
char* src = reinterpret_cast<char*>(buf->out());
193193
const size_t len_in_bytes = buf->length() * sizeof(buf->out()[0]);
194194

195-
if (buf->IsAllocated())
195+
if (buf->IsAllocated()) {
196196
ret = New(env, src, len_in_bytes);
197-
else if (!buf->IsInvalidated())
198-
ret = Copy(env, src, len_in_bytes);
199-
200-
if (ret.IsEmpty())
201-
return ret;
202-
203-
if (buf->IsAllocated())
197+
// new always takes ownership of src
204198
buf->Release();
199+
} else if (!buf->IsInvalidated()) {
200+
ret = Copy(env, src, len_in_bytes);
201+
}
205202

206203
return ret;
207204
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.