From 3b318805ec253161492e32016cf391b789b24b67 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 19 May 2016 18:15:08 +0200 Subject: [PATCH] don't leak buffers --- js/common/bootstrap/modules/buffer.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/js/common/bootstrap/modules/buffer.js b/js/common/bootstrap/modules/buffer.js index e38ee60546..39a726a65d 100644 --- a/js/common/bootstrap/modules/buffer.js +++ b/js/common/bootstrap/modules/buffer.js @@ -204,19 +204,14 @@ function Buffer(subject, encoding, offset) { 'array or string.'); } - if (this.length > Buffer.poolSize) { + // note: the following condition means we'll always create a SlowBuffer + // for non-empty lengths. This is required to circumvent using the shared + // pool, which is only allocated but never freed (and therefore leaks + // memory on shutdown) + if (this.length > 0) { // Big buffer, just alloc one. this.parent = new SlowBuffer(this.length); this.offset = 0; - - } else if (this.length > 0) { - // Small buffer. - if (!pool || pool.length - pool.used < this.length) allocPool(); - this.parent = pool; - this.offset = pool.used; - pool.used += this.length; - if (pool.used & 7) pool.used = (pool.used + 8) & ~7; - } else { // Zero-length buffer this.parent = new SlowBuffer(0);