smalloc: check if obj has external data
authorVladimir Kurchatkin <vladimir.kurchatkin@gmail.com>
Fri, 31 Oct 2014 22:15:12 +0000 (01:15 +0300)
committerTrevor Norris <trev.norris@gmail.com>
Wed, 5 Nov 2014 08:33:00 +0000 (00:33 -0800)
PR-URL: https://github.com/joyent/node/pull/8655
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
lib/smalloc.js
test/simple/test-smalloc.js

index ba042c6..fd82ba8 100644 (file)
@@ -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);
 }
index ea6f7bf..091f5aa 100644 (file)
@@ -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({});
 });