From 254958046a796db963708ac72d1c5430b118b6a4 Mon Sep 17 00:00:00 2001 From: Randy Jordan Date: Sat, 18 Oct 2025 11:39:47 -0500 Subject: [PATCH] Added arena free macro for cleanup and clarity --- include/mem.h | 1 + tests/05_arena_new.c | 2 +- tests/06_arena_nozero.c | 2 +- tests/08_arena_exception.c | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/mem.h b/include/mem.h index b70421b..2a7190d 100644 --- a/include/mem.h +++ b/include/mem.h @@ -44,5 +44,6 @@ extern void *mem_arena_alloc(int flags, Arena *a, mem_arena_new((flags), (nbytes), __FILE__, __LINE__) #define ARENA_ALLOC(flags, a, nbytes, align, count) \ mem_arena_alloc((flags), (a), (nbytes), (align), (count), __FILE__, __LINE__) +#define ARENA_FREE(a) mem_free(a.beg, __FILE__, __LINE__) #endif diff --git a/tests/05_arena_new.c b/tests/05_arena_new.c index b3662a6..8453961 100644 --- a/tests/05_arena_new.c +++ b/tests/05_arena_new.c @@ -7,6 +7,6 @@ int main(void){ Arena a = ARENA(0,nbytes); ASSERTED(a.beg != NULL); ASSERTED( mem_is_zero(a.beg, nbytes)); - FREE(a.beg); + ARENA_FREE(a); return EXIT_SUCCESS; } diff --git a/tests/06_arena_nozero.c b/tests/06_arena_nozero.c index b1cd812..39b5d70 100644 --- a/tests/06_arena_nozero.c +++ b/tests/06_arena_nozero.c @@ -7,6 +7,6 @@ int main(void){ Arena a = ARENA(NOZERO,nbytes); ASSERTED(a.beg != NULL); ASSERTED( !mem_is_zero(a.beg, nbytes)); - FREE(a.beg); + ARENA_FREE(a); return EXIT_SUCCESS; } diff --git a/tests/08_arena_exception.c b/tests/08_arena_exception.c index 238a9db..5405fa1 100644 --- a/tests/08_arena_exception.c +++ b/tests/08_arena_exception.c @@ -11,7 +11,7 @@ int main(void){ a = ARENA(0,nbytes); /* try 1GB */ if (!a.beg) RAISE(OOM); - free(a.beg); + ARENA_FREE(a); } EXCEPT(OOM) { /* handle memory failure gracefully */ @@ -20,7 +20,7 @@ int main(void){ } FINALLY { /* cleanup if needed, runs always */ - if (a.beg) free(a.beg); + if (a.beg) ARENA_FREE(a); } END_TRY;