diff --git a/src/node_http2.cc b/src/node_http2.cc index 9047171e114606..ab1c73777941a5 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -557,11 +557,20 @@ class Http2Session::MemoryAllocatorInfo { if (mem != nullptr) { // Adjust the memory info counter. - session->current_nghttp2_memory_ += size - previous_size; + // TODO(addaleax): Avoid the double bookkeeping we do with + // current_nghttp2_memory_ + AdjustAmountOfExternalAllocatedMemory + // and provide versions of our memory allocation utilities that take an + // Environment*/Isolate* parameter and call the V8 method transparently. + const int64_t new_size = size - previous_size; + session->current_nghttp2_memory_ += new_size; + session->env()->isolate()->AdjustAmountOfExternalAllocatedMemory( + new_size); *reinterpret_cast(mem) = size; mem += sizeof(size_t); } else if (size == 0) { session->current_nghttp2_memory_ -= previous_size; + session->env()->isolate()->AdjustAmountOfExternalAllocatedMemory( + -static_cast(previous_size)); } return mem; @@ -571,6 +580,8 @@ class Http2Session::MemoryAllocatorInfo { size_t* original_ptr = reinterpret_cast( static_cast(ptr) - sizeof(size_t)); session->current_nghttp2_memory_ -= *original_ptr; + session->env()->isolate()->AdjustAmountOfExternalAllocatedMemory( + -static_cast(*original_ptr)); *original_ptr = 0; }