Skip to content

Commit

Permalink
buffer: Don't assign .parent if none exists
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
  • Loading branch information
trevnorris committed Mar 9, 2015
1 parent e795138 commit 8070b1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 8070b1f

Please sign in to comment.