File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed
Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ class Engine {
1616 }
1717 this . wasmInstance = args . wasmInstance ;
1818 const arr = args . wasmInstance . exports . memory . buffer ;
19- const mgr = new mmgr . MemoryManager ( arr , args . wasmInstance . exports . __heap_base ) ;
19+ const mgr = new mmgr . MemoryManager ( arr , Number ( args . wasmInstance . exports . __heap_base ) ) ;
2020 this . mgr = mgr ;
2121
2222 this . functional = this . F = new Functional ( {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ class MemoryManager {
66 this . array = array ;
77
88 if ( heapBase == null ) heapBase = 0 ;
9+ else heapBase = Number ( heapBase ) ;
910
1011 this . ptrToSlot = new Map ( ) ;
1112
@@ -121,6 +122,10 @@ class MemoryManager {
121122
122123 free ( ptr ) {
123124 const slot = this . ptrToSlot . get ( ptr ) ;
125+ if ( slot == null ) {
126+ throw new Error ( `no slot found for ptr ${ ptr } ` ) ;
127+ }
128+ this . ptrToSlot . delete ( ptr ) ;
124129 slot . free ( ) ;
125130 }
126131}
Original file line number Diff line number Diff line change 1+ const algovivo = require ( "algovivo" ) ;
2+
3+ test ( "malloc free with non-numeric heapBase" , ( ) => {
4+ // simulate WebAssembly.Global which has valueOf() but is an object
5+ const heapBase = { valueOf : ( ) => 16 } ;
6+ const buffer = new ArrayBuffer ( 1024 ) ;
7+ const mgr = new algovivo . mmgrten . mmgr . MemoryManager ( buffer , heapBase ) ;
8+
9+ const ptr = mgr . malloc ( 32 ) ;
10+ const numericPtr = Number ( ptr ) ;
11+ mgr . free ( numericPtr ) ;
12+ } ) ;
You can’t perform that action at this time.
0 commit comments