about summary refs log tree commit diff stats
path: root/src/js/javascript.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-19 18:32:03 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-19 18:32:03 +0200
commit070cfca46f60c3a00fe6dd66457f454a1a217897 (patch)
treebe233cfdfafd48834dac867eaaadf201fe839a7e /src/js/javascript.nim
parent17097052794aef56bbc55327d3e6c84ae1c67378 (diff)
downloadchawan-070cfca46f60c3a00fe6dd66457f454a1a217897.tar.gz
Fix memory leak with alt pointers
Must unref them if unused.
Diffstat (limited to 'src/js/javascript.nim')
-rw-r--r--src/js/javascript.nim7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim
index fb020e5c..e868dde3 100644
--- a/src/js/javascript.nim
+++ b/src/js/javascript.nim
@@ -37,6 +37,7 @@ import bindings/quickjs
 
 export opt
 export options
+export tables
 
 export
   JS_NULL, JS_UNDEFINED, JS_FALSE, JS_TRUE, JS_EXCEPTION, JS_UNINITIALIZED
@@ -1722,7 +1723,7 @@ proc nim_finalize_for_js[T](obj: T) =
           fin[](val)
         # Then clear val's opaque, so that our refcount isn't decreased again.
         JS_SetOpaque(val, nil)
-      tables.del(rtOpaque.plist, cast[pointer](obj))
+      rtOpaque.plist.del(cast[pointer](obj))
       # Decrement jsvalue's refcount. This is needed in both cases to
       # trigger the JS finalizer and free the JS value.
       JS_FreeValueRT(rt, val)
@@ -1930,6 +1931,10 @@ macro registerType*(ctx: typed, t: typed, parent: JSClassID = 0,
         GC_unref(cast[`t`](opaque))
         let rtOpaque = rt.getOpaque()
         rtOpaque.plist.del(opaque)
+        let p = JS_VALUE_GET_PTR(`val`)
+        if p in rtOpaque.altplist:
+          GC_unref(cast[`t`](rtOpaque.altplist[p]))
+          rtOpaque.altplist.del(p)
   )
 
   let endstmts = newStmtList()