Skip to content

Commit

Permalink
smalloc: check if obj has external data
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node-v0.x-archive#8655
Reviewed-by: Trevor Norris <[email protected]>
  • Loading branch information
vkurchatkin authored and trevnorris committed Nov 5, 2014
1 parent 849fcde commit f65a5cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/smalloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ function dispose(obj) {
throw new TypeError('obj must be an Object');
if (util.isBuffer(obj))
throw new TypeError('obj cannot be a Buffer');
if (!smalloc.hasExternalData(obj))
throw new Error('obj has no external array data');

smalloc.dispose(obj);
}
8 changes: 6 additions & 2 deletions test/simple/test-smalloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,15 @@ for (var i = 0; i < 5; i++)

// only allow object to be passed to dispose
assert.throws(function() {
alloc.dispose(null);
smalloc.dispose(null);
});


// can't dispose a Buffer
assert.throws(function() {
alloc.dispose(new Buffer());
smalloc.dispose(new Buffer());
});

assert.throws(function() {
smalloc.dispose({});
});

0 comments on commit f65a5cb

Please sign in to comment.