From fe3a2b33165ee0d7765ba4e838e9c4875d8fb195 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 2 May 2023 20:59:49 -0700 Subject: gc: use single allocation for prot_array. * gc.c (prot_array): Add self pointer; arr member becomes flexible array. (prot_array_mark): We now check the handle itself for null, because the whole thing is freed. (prot_array_free): Function removed. (prot_array_ops): Wire cobj_destroy_free_op in place of prot_array_free. This fixes a memory leak because prot_array_free was not freeing the handle, only the array. (gc_prot_array_alloc): Fix to allocate everything in one swoop and store the self-pointer in the named member rather than arr[-1]. The self argument is not required; we drop it. The size argument cannot be anywhere near INT_PTR_MAX, because such an array wouldn't fit into virtual memory, so it is always safe to add a small value to the size. (prot_array_free): Obtain the self-pointer, and free the handle, replacing it with a null pointer. * gc.h (gc_prot_array_alloc): Declaration updated. * lib.c (ssort_vec): Don't pass self to gc_prot_array_alloc. * lib.h (container): New macro. --- lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index bea09ea3..2e9de482 100644 --- a/lib.c +++ b/lib.c @@ -10922,7 +10922,7 @@ static void mergesort(val vec, val lessfun, val keyfun, cnum from, cnum to, static void ssort_vec(val vec, val lessfun, val keyfun, val self) { cnum len = c_fixnum(length(vec), self); - val *aux = gc_prot_array_alloc(len, self); + val *aux = gc_prot_array_alloc(len); mergesort(vec, lessfun, keyfun, 0, len, aux); gc_prot_array_free(aux); } -- cgit v1.2.3