summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-03-25 18:04:59 +0100
committerJo-Philipp Wich <jo@mein.io>2021-03-25 19:07:59 +0100
commit00d941954366bb8db14f1ee7d272814a986e4262 (patch)
tree88b0f22385937daf12408250834c1171fd7effd9
parent20a3763d0a9a5efe6478595fe5590d47bffa90fe (diff)
vm: fix further memory leaks in trace mode
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--object.c16
-rw-r--r--vm.c20
2 files changed, 30 insertions, 6 deletions
diff --git a/object.c b/object.c
index 0616350..7748744 100644
--- a/object.c
+++ b/object.c
@@ -475,3 +475,19 @@ uc_ressource_prototype(json_object *jso)
return type ? type->proto : NULL;
}
+
+
+#ifdef __GNUC__
+
+__attribute__((destructor))
+static void uc_ressource_types_free(void)
+{
+ size_t i;
+
+ for (i = 0; i < res_types.count; i++)
+ uc_value_put(res_types.entries[i].proto->header.jso);
+
+ uc_vector_clear(&res_types);
+}
+
+#endif
diff --git a/vm.c b/vm.c
index 4fd376e..6704982 100644
--- a/vm.c
+++ b/vm.c
@@ -266,6 +266,7 @@ uc_vm_frame_dump(uc_vm *vm, uc_callframe *frame)
uc_function *function;
uc_closure *closure;
uc_upvalref *ref;
+ json_object *v;
size_t i;
fprintf(stderr, " [*] CALLFRAME[%zx]\n",
@@ -281,10 +282,15 @@ uc_vm_frame_dump(uc_vm *vm, uc_callframe *frame)
fprintf(stderr, " |- %zu constants\n",
chunk->constants.isize);
- for (i = 0; i < chunk->constants.isize; i++)
+ for (i = 0; i < chunk->constants.isize; i++) {
+ v = uc_chunk_get_constant(chunk, i);
+
fprintf(stderr, " | [%zu] %s\n",
i,
- json_object_to_json_string(uc_chunk_get_constant(chunk, i)));
+ json_object_to_json_string(v));
+
+ uc_value_put(v);
+ }
closure = frame->closure;
function = closure->function;
@@ -294,22 +300,23 @@ uc_vm_frame_dump(uc_vm *vm, uc_callframe *frame)
for (i = 0; i < function->nupvals; i++) {
ref = closure->upvals[i];
+ v = uc_chunk_debug_get_variable(chunk, 0, i, true);
if (ref->closed)
fprintf(stderr, " [%zu] <%p> %s {closed} %s\n",
i,
ref,
- json_object_to_json_string(
- uc_chunk_debug_get_variable(chunk, 0, i, true)),
+ json_object_to_json_string(v),
json_object_to_json_string(ref->value));
else
fprintf(stderr, " [%zu] <%p> %s {open[%zu]} %s\n",
i,
ref,
- json_object_to_json_string(
- uc_chunk_debug_get_variable(chunk, 0, i, true)),
+ json_object_to_json_string(v),
ref->slot,
json_object_to_json_string(vm->stack.entries[ref->slot]));
+
+ uc_value_put(v);
}
}
}
@@ -2224,6 +2231,7 @@ uc_vm_execute(uc_vm *vm, uc_function *fn, uc_prototype *globals, json_object *mo
fn->source, 0, true);
fprintf(stderr, "%s", msg);
+ free(msg);
uc_vm_frame_dump(vm, frame);
}