summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-10-23 10:29:55 +0200
committerJo-Philipp Wich <jo@mein.io>2021-10-23 10:32:56 +0200
commit0f022aae0c6008fe6f2219871d32dca8b9105066 (patch)
treee1ccc24b8b4d61d896db57bfa447202de264f12b
parent9041e2403d98fdb54206c23bd684a7da6fb63026 (diff)
lib: increase refcount when returning cached module instance
Subsequent requires of the same module returned the cached module instance without increasing the refcount, leading to use-after-free on VM tear down or garbage collection cycles. Solve this issue by properly incrementing the refcount before returning the cached module instance. Fixes: #25 Fixes: 96f140b ("lib, vm: ensure that require() compiles modules only once") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--lib.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 0b1f663..2c91d1d 100644
--- a/lib.c
+++ b/lib.c
@@ -1597,7 +1597,7 @@ uc_require_path(uc_vm_t *vm, const char *path_template, const char *name, uc_val
bool rv;
modtable = ucv_property_get(uc_vm_scope_get(vm), "modules");
- *res = ucv_object_get(modtable, name, &rv);
+ *res = ucv_get(ucv_object_get(modtable, name, &rv));
if (rv)
goto out;