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: #5494
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: targos - Michaël Zasso <mic.besace@gmail.com>
  • Loading branch information
ofrobots authored and Ali Sheikh committed Mar 4, 2016
1 parent 8cf9400 commit 206a81f
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 206a81f

Please sign in to comment.