From c65b2eff6de4e62fc90c5295e5528faf4925535c Mon Sep 17 00:00:00 2001 From: anth64 Date: Wed, 28 Jan 2026 00:45:39 +0100 Subject: [PATCH] fix: handle realloc to zero capacity * Call stk_module_free_memory() when new_capacity is 0. --- src/module.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/module.c b/src/module.c index 0fd729d..f853414 100644 --- a/src/module.c +++ b/src/module.c @@ -195,6 +195,11 @@ int stk_module_realloc_memory(size_t new_capacity) stk_module_func *old_inits = stk_inits; stk_module_func *old_shutdowns = stk_shutdowns; + if (new_capacity == 0) { + stk_module_free_memory(); + return 0; + } + new_module_ids = realloc(stk_module_ids, new_capacity * sizeof(*stk_module_ids)); new_handles = realloc(stk_handles, new_capacity * sizeof(*new_handles));