From 8070b1ff9943a53d520bf47ca1dd541f56a3c830 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Mon, 9 Mar 2015 12:28:31 -0600 Subject: [PATCH] buffer: Don't assign .parent if none exists The .parent property of the allocated buffer should remain undefined in the case that it's not a slice. Also included test to verify this. PR-URL: https://github.com/iojs/io.js/pull/1109 Reviewed-By: Chris Dickinson Reviewed-By: Fedor Indutny --- lib/buffer.js | 5 ++++- test/parallel/test-buffer.js | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/buffer.js b/lib/buffer.js index 5427a5a5a66e29..dde229a2ea99ab 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -141,7 +141,10 @@ function fromJsonObject(that, object) { function allocate(that, length) { var fromPool = length !== 0 && length <= Buffer.poolSize >>> 1; - that.parent = fromPool ? palloc(that, length) : alloc(that, length); + if (fromPool) + that.parent = palloc(that, length); + else + alloc(that, length); that.length = length; } diff --git a/test/parallel/test-buffer.js b/test/parallel/test-buffer.js index f4e89e2a579733..9b16b7b028476a 100644 --- a/test/parallel/test-buffer.js +++ b/test/parallel/test-buffer.js @@ -1174,3 +1174,8 @@ assert.throws(function() { // Regression test for https://github.com/iojs/io.js/issues/649. assert.throws(function() { Buffer(1422561062959).toString('utf8'); }); + +var ps = Buffer.poolSize; +Buffer.poolSize = 0; +assert.equal(Buffer(1).parent, undefined); +Buffer.poolSize = ps;