Branch data Line data Source code
1 : : #include "precizer.h"
2 : :
3 : : /**
4 : : * @brief Free a NULL-terminated string array and reset the caller-owned pointer
5 : : *
6 : : * @param[in,out] array_ptr Pointer to the array pointer to free
7 : : *
8 : : * @note Passing `NULL` or a pointer to `NULL` is allowed
9 : : */
10 : 1824 : void free_string_array(char ***array_ptr)
11 : : {
12 [ + - + + ]: 1824 : if(array_ptr == NULL || *array_ptr == NULL)
13 : : {
14 : 1592 : return;
15 : : }
16 : :
17 : 232 : char **array = *array_ptr;
18 : :
19 [ + + ]: 612 : for(size_t i = 0; array[i] != NULL; i++)
20 : : {
21 : 380 : free(array[i]);
22 : 380 : array[i] = NULL;
23 : : }
24 : :
25 : 232 : free(array);
26 : 232 : *array_ptr = NULL;
27 : : }
|