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

smalloc: don't allow to dispose typed arrays #8743

Closed
wants to merge 1 commit into from
Closed

smalloc: don't allow to dispose typed arrays #8743

wants to merge 1 commit into from

Conversation

vkurchatkin
Copy link

Typed arrays behave as objects with external data in some cases, but disposing them is a bad idea:

var smalloc = require('smalloc');

var ab = new ArrayBuffer(3);
var a1 = new Uint8Array(ab);
var a2 = new Uint8Array(ab);

for (var i = 0; i < a1.length; i++)
  a1[i] = 6;

console.log(a1);
console.log(a2);

smalloc.dispose(a1);

console.log(a1);
console.log(a2);

// node(72543,0x7fff7ada2310) malloc: *** error for object 0x100f0b2f0: pointer being freed was not allocated
// *** set a breakpoint in malloc_error_break to debug
// Abort trap: 6

/cc @trevnorris

@trevnorris
Copy link

Nice catch. Does Value::IsTypedArray() also catch DataView?

@vkurchatkin
Copy link
Author

@trevnorris it doesn't, but Value::IsArrayBufferView does. smalloc.hasExternalData returns false for DataView, so it's not necessary

@vkurchatkin
Copy link
Author

@trevnorris ping

trevnorris pushed a commit that referenced this pull request Nov 26, 2014
PR-URL: #8743
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
@trevnorris
Copy link

Thanks much. Landed in bf3e0f4.

@trevnorris trevnorris closed this Nov 26, 2014
piscisaureus pushed a commit to piscisaureus/node2 that referenced this pull request Dec 9, 2014
PR-URL: nodejs/node-v0.x-archive#8743
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
piscisaureus pushed a commit to nodejs/node that referenced this pull request Dec 9, 2014
PR-URL: nodejs/node-v0.x-archive#8743
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants