From f65a5cbcde51ef7da0ff5617dcab1a164b9a217b Mon Sep 17 00:00:00 2001 From: Vladimir Kurchatkin Date: Sat, 1 Nov 2014 01:15:12 +0300 Subject: [PATCH] smalloc: check if obj has external data PR-URL: https://github.com/joyent/node/pull/8655 Reviewed-by: Trevor Norris --- lib/smalloc.js | 2 ++ test/simple/test-smalloc.js | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/smalloc.js b/lib/smalloc.js index ba042c6c4c..fd82ba8c42 100644 --- a/lib/smalloc.js +++ b/lib/smalloc.js @@ -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); } diff --git a/test/simple/test-smalloc.js b/test/simple/test-smalloc.js index ea6f7bf4ad..091f5aa7e0 100644 --- a/test/simple/test-smalloc.js +++ b/test/simple/test-smalloc.js @@ -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({}); });