Message ID | 1582615812-6738-1-git-send-email-damjan.skvarc@gmail.com |
---|---|
State | Deferred |
Headers | show |
Series | [ovs-dev,V2] util: helper function for deallocating dynamically allocated array of strings | expand |
On Tue, Feb 25, 2020 at 08:30:12AM +0100, Damijan Skvarc wrote: > Hi Ben and thanks for letting me know about "x" prefix nomenclature, I > was not aware about it. Thanks also for suggesting more appropriate > function name, it much more descriptive. I am sending V2 patch You're welcome. Thanks for the update. I would prefer to see this either as the first of a series of patches that adds users, or to have at least one user added in the same patch. Otherwise, we end up with a new function that does not have a user, which is not ideal.
diff --git a/lib/util.c b/lib/util.c index 830e145..5b0b477 100644 --- a/lib/util.c +++ b/lib/util.c @@ -321,6 +321,18 @@ free_cacheline(void *p) free_size_align(p); } +/* free array of char pointers and array itself */ +void +free_strings(char **strs, size_t size) +{ + size_t i; + + for (i = 0; i < size; i++) { + free(strs[i]); + } + free(strs); +} + void * xmalloc_pagealign(size_t size) { diff --git a/lib/util.h b/lib/util.h index 7ad8758..fc989ce 100644 --- a/lib/util.h +++ b/lib/util.h @@ -163,6 +163,7 @@ void *x2nrealloc(void *p, size_t *n, size_t s); void *xmalloc_cacheline(size_t) MALLOC_LIKE; void *xzalloc_cacheline(size_t) MALLOC_LIKE; void free_cacheline(void *); +void free_strings(char **, size_t); void ovs_strlcpy(char *dst, const char *src, size_t size); void ovs_strzcpy(char *dst, const char *src, size_t size);
Hi Ben and thanks for letting me know about "x" prefix nomenclature, I was not aware about it. Thanks also for suggesting more appropriate function name, it much more descriptive. I am sending V2 patch Signed-off-by: Damijan Skvarc <damjan.skvarc@gmail.com> --- lib/util.c | 12 ++++++++++++ lib/util.h | 1 + 2 files changed, 13 insertions(+)