From 96b1f1fd261109524f6a804bc0a7b24ea4e3d772 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Fri, 9 May 2025 19:09:12 +0200 Subject: [PATCH] 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. --- include/haproxy/tools.h | 2 ++ src/tools.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) 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