Files
codebase-memory-mcp/src
Martin Vogelandmap588 8fe1310779 feat(platform): add safe_free / safe_str_free / safe_buf_free / safe_grow
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>
2026-05-08 21:57:41 +02:00
..
2026-04-15 23:56:03 +02:00