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 : 2220 : void free_string_array(char ***array_ptr)
11 : : {
12 [ + - + + ]: 2220 : if(array_ptr == NULL || *array_ptr == NULL)
13 : : {
14 : 1908 : return;
15 : : }
16 : :
17 : 312 : char **array = *array_ptr;
18 : :
19 [ + + ]: 772 : for(size_t i = 0; array[i] != NULL; i++)
20 : : {
21 : 460 : free(array[i]);
22 : 460 : array[i] = NULL;
23 : : }
24 : :
25 : 312 : free(array);
26 : 312 : *array_ptr = NULL;
27 : : }
|