Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit f65a5cb

Browse files
vkurchatkintrevnorris
authored andcommitted
smalloc: check if obj has external data
PR-URL: #8655 Reviewed-by: Trevor Norris <[email protected]>
1 parent 849fcde commit f65a5cb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/smalloc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ function dispose(obj) {
8686
throw new TypeError('obj must be an Object');
8787
if (util.isBuffer(obj))
8888
throw new TypeError('obj cannot be a Buffer');
89+
if (!smalloc.hasExternalData(obj))
90+
throw new Error('obj has no external array data');
8991

9092
smalloc.dispose(obj);
9193
}

test/simple/test-smalloc.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,15 @@ for (var i = 0; i < 5; i++)
314314

315315
// only allow object to be passed to dispose
316316
assert.throws(function() {
317-
alloc.dispose(null);
317+
smalloc.dispose(null);
318318
});
319319

320320

321321
// can't dispose a Buffer
322322
assert.throws(function() {
323-
alloc.dispose(new Buffer());
323+
smalloc.dispose(new Buffer());
324+
});
325+
326+
assert.throws(function() {
327+
smalloc.dispose({});
324328
});

0 commit comments

Comments
 (0)