Safe buffer free: frees a heap array and zeros its element count. * Use for dynamic arrays paired with a size_t count. */
| 53 | /* Safe buffer free: frees a heap array and zeros its element count. |
| 54 | * Use for dynamic arrays paired with a size_t count. */ |
| 55 | static inline void safe_buf_free_impl(void **buf, size_t *count) { |
| 56 | if (buf && *buf) { |
| 57 | free(*buf); |
| 58 | *buf = NULL; |
| 59 | } |
| 60 | if (count) { |
| 61 | *count = 0; |
| 62 | } |
| 63 | } |
| 64 | #define safe_buf_free(buf, countp) safe_buf_free_impl((void **)(void *)&(buf), (countp)) |
| 65 | |
| 66 | /* Safe grow: doubles capacity and reallocs when count reaches cap. |
nothing calls this directly
no outgoing calls
no test coverage detected