Skip to content

Commit

Permalink
buffer: avoid undefined behaviour
Browse files Browse the repository at this point in the history
Avoid 'delete this' as it can be hazardous and/or dependent on
implementations.

PR-URL: nodejs#5494
Reviewed-By: bnoordhuis - Ben Noordhuis <[email protected]>
Reviewed-By: targos - Michaël Zasso <[email protected]>
  • Loading branch information
ofrobots authored and Ali Sheikh committed Mar 3, 2016
1 parent 907386f commit 67e2ff3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,18 @@ CallbackInfo::~CallbackInfo() {

void CallbackInfo::WeakCallback(
const WeakCallbackInfo<CallbackInfo>& data) {
data.GetParameter()->WeakCallback(
CallbackInfo* self = data.GetParameter();
self->WeakCallback(
data.GetIsolate(),
static_cast<char*>(data.GetInternalField(kBufferInternalFieldIndex)));
delete self;
}


void CallbackInfo::WeakCallback(Isolate* isolate, char* const data) {
callback_(data, hint_);
int64_t change_in_bytes = -static_cast<int64_t>(sizeof(*this));
isolate->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);

delete this;
}


Expand Down

0 comments on commit 67e2ff3

Please sign in to comment.