From: William Lallemand Date: Fri, 9 May 2025 17:09:12 +0000 (+0200) Subject: MINOR: tools: ha_freearray() frees an array of string X-Git-Tag: v3.2-dev16~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=96b1f1fd261109524f6a804bc0a7b24ea4e3d772;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/include/haproxy/tools.h b/include/haproxy/tools.h index 45e0ff994..abb8f736d 100644 --- a/include/haproxy/tools.h +++ b/include/haproxy/tools.h @@ -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 */ diff --git a/src/tools.c b/src/tools.c index 313396823..97b8d65b4 100644 --- a/src/tools.c +++ b/src/tools.c @@ -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