From dd9c7723fafc8b326188efa86efe00bcbe5abcfd Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Wed, 17 Dec 2014 01:08:56 +0100 Subject: [PATCH] shared: strv - add strv_clear() This frees the elements of the strv without freeing the strv itself. --- src/shared/strv.c | 7 ++++++- src/shared/strv.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/shared/strv.c b/src/shared/strv.c index fdb658c0a..f86dddaf8 100644 --- a/src/shared/strv.c +++ b/src/shared/strv.c @@ -69,7 +69,7 @@ char *strv_find_startswith(char **l, const char *name) { return NULL; } -void strv_free(char **l) { +void strv_clear(char **l) { char **k; if (!l) @@ -78,6 +78,11 @@ void strv_free(char **l) { for (k = l; *k; k++) free(*k); + *l = NULL; +} + +void strv_free(char **l) { + strv_clear(l); free(l); } diff --git a/src/shared/strv.h b/src/shared/strv.h index 2c0280b71..9e5b1bb8b 100644 --- a/src/shared/strv.h +++ b/src/shared/strv.h @@ -34,6 +34,8 @@ void strv_free(char **l); DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free); #define _cleanup_strv_free_ _cleanup_(strv_freep) +void strv_clear(char **l); + char **strv_copy(char * const *l); unsigned strv_length(char * const *l) _pure_; -- 2.30.2