mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-11-08 08:53:43 +08:00
Centralize repetitive heap-management patterns into four wrappers alongside the existing safe_realloc: - safe_free(ptr): frees and NULLs a pointer to prevent double-free / use-after-free - safe_str_free(&str): frees a const char * and NULLs it without forcing the caller to cast away const at every site - safe_buf_free(buf, &count): frees a heap array and zeros the paired count, so the dangling-array / nonzero-count footgun cannot survive - safe_grow(arr, n, cap, factor): one-line capacity-doubling realloc for arrays whose elements do not own additional heap memory; documents the safe_realloc free-on-failure semantic so arrays of owned pointers keep using a manual realloc+cleanup pattern Cherry-picked from #209's platform.h additions; the rest of #209 duplicated work that landed via #206 and #207, so closing that PR in favor of this targeted commit. Co-authored-by: map588 <map588@pitt.edu>