Browse Source

buffer: avoid undefined behaviour

Avoid 'delete this' as it can be hazardous and/or dependent on
implementations.

PR-URL: https://github.com/nodejs/node/pull/5494
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: targos - Michaël Zasso <mic.besace@gmail.com>
process-exit-stdio-flushing
Ali Ijaz Sheikh 9 years ago
committed by Ali Sheikh
parent
commit
206a81fb14
  1. 6
      src/node_buffer.cc

6
src/node_buffer.cc

@ -139,9 +139,11 @@ 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;
}
@ -149,8 +151,6 @@ 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;
}

Loading…
Cancel
Save