Skip to content

Commit 206a81f

Browse files
ofrobotsAli Sheikh
authored andcommitted
buffer: avoid undefined behaviour
Avoid 'delete this' as it can be hazardous and/or dependent on implementations. PR-URL: #5494 Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: targos - Michaël Zasso <mic.besace@gmail.com>
1 parent 8cf9400 commit 206a81f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/node_buffer.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,18 @@ CallbackInfo::~CallbackInfo() {
139139

140140
void CallbackInfo::WeakCallback(
141141
const WeakCallbackInfo<CallbackInfo>& data) {
142-
data.GetParameter()->WeakCallback(
142+
CallbackInfo* self = data.GetParameter();
143+
self->WeakCallback(
143144
data.GetIsolate(),
144145
static_cast<char*>(data.GetInternalField(kBufferInternalFieldIndex)));
146+
delete self;
145147
}
146148

147149

148150
void CallbackInfo::WeakCallback(Isolate* isolate, char* const data) {
149151
callback_(data, hint_);
150152
int64_t change_in_bytes = -static_cast<int64_t>(sizeof(*this));
151153
isolate->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
152-
153-
delete this;
154154
}
155155

156156

0 commit comments

Comments
 (0)