MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / safe_realloc

Function safe_realloc

src/foundation/platform.h:22–32  ·  view source on GitHub ↗

Safe realloc: frees old pointer on failure instead of leaking it. * Returns NULL on allocation failure (old memory is freed). */

Source from the content-addressed store, hash-verified

20/* Safe realloc: frees old pointer on failure instead of leaking it.
21 * Returns NULL on allocation failure (old memory is freed). */
22static inline void *safe_realloc(void *ptr, size_t size) {
23 enum { SAFE_REALLOC_MIN = 1 };
24 if (size == 0) {
25 size = SAFE_REALLOC_MIN;
26 }
27 void *tmp = realloc(ptr, size);
28 if (!tmp) {
29 free(ptr);
30 }
31 return tmp;
32}
33
34/* Safe free: frees and NULLs a pointer to prevent double-free / use-after-free.
35 * Use via the safe_free() macro so the caller's pointer is actually cleared. */

Callers 15

wd_pushFunction · 0.85
cbm_store_list_projectsFunction · 0.85
find_nodes_genericFunction · 0.85
find_edges_genericFunction · 0.85
coverage_query_rowsFunction · 0.85
cbm_store_coverage_getFunction · 0.85
cbm_store_list_filesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected