]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: ha_freearray() frees an array of string
authorWilliam Lallemand <wlallemand@haproxy.com>
Fri, 9 May 2025 17:09:12 +0000 (19:09 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Fri, 9 May 2025 17:12:05 +0000 (19:12 +0200)
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
src/tools.c

index 45e0ff994f9f9ade484d0a26ba451f67d812eea7..abb8f736df52115c3a6a7a6d16c2df93758c3860 100644 (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 */
index 313396823ce71436d05afa90dd8ba81d93c6d15d..97b8d65b4d0df1d3007408c9b501e84d956dbb0e 100644 (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