From 0ec88a3573a882f7c8cd23b011e42ffa7e01397d Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sat, 20 Dec 2014 10:08:23 -0500 Subject: shared: strv - add strv_clear() This frees the elements of the strv without freeing the strv itself. Signed-off-by: Anthony G. Basile --- 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 85ae556c16..5cfab8f23e 100644 --- a/src/shared/strv.c +++ b/src/shared/strv.c @@ -26,7 +26,7 @@ #include "util.h" #include "strv.h" -void strv_free(char **l) { +void strv_clear(char **l) { char **k; if (!l) @@ -35,6 +35,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 22c8132c57..94bdbe62aa 100644 --- a/src/shared/strv.h +++ b/src/shared/strv.h @@ -28,6 +28,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_; -- cgit v1.2.3-54-g00ecf