MINOR: tools: ha_freearray() frees an array of string

ha_freearray() is a new function which free() an array of strings
terminated by a NULL entry.

The pointer to the array will be free and set to NULL.
This commit is contained in:
William Lallemand 2025-05-09 19:09:12 +02:00
parent 311e0aa5c7
commit 96b1f1fd26
2 changed files with 18 additions and 0 deletions

View File

@ -1390,4 +1390,6 @@ static inline const char *errname(int err_num, char **out)
int path_base(const char *path, const char *base, char *dst, char **err);
void ha_freearray(char ***array);
#endif /* _HAPROXY_TOOLS_H */

View File

@ -7318,6 +7318,22 @@ out:
return err_code;
}
/*
* free() an array of strings terminated by a NULL entry
* set the pointer to NULL
*/
void ha_freearray(char ***array)
{
int i;
char **r = *array;
for (i = 0; r && r[i]; i++) {
free(r[i]);
r[i] = NULL;
}
*array = NULL;
}
/*
* Local variables:
* c-indent-level: 8