Skip to content

Commit 8070b1f

Browse files
committed
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: #1109 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent e795138 commit 8070b1f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/buffer.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ function fromJsonObject(that, object) {
141141

142142
function allocate(that, length) {
143143
var fromPool = length !== 0 && length <= Buffer.poolSize >>> 1;
144-
that.parent = fromPool ? palloc(that, length) : alloc(that, length);
144+
if (fromPool)
145+
that.parent = palloc(that, length);
146+
else
147+
alloc(that, length);
145148
that.length = length;
146149
}
147150

test/parallel/test-buffer.js

+5
Original file line numberDiff line numberDiff line change
@@ -1174,3 +1174,8 @@ assert.throws(function() {
11741174

11751175
// Regression test for https://github.com/iojs/io.js/issues/649.
11761176
assert.throws(function() { Buffer(1422561062959).toString('utf8'); });
1177+
1178+
var ps = Buffer.poolSize;
1179+
Buffer.poolSize = 0;
1180+
assert.equal(Buffer(1).parent, undefined);
1181+
Buffer.poolSize = ps;

0 commit comments

Comments
 (0)