summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-10-15 10:02:35 -0400
committerLennart Poettering <lennart@poettering.net>2015-10-19 23:13:07 +0200
commitab84f5b95e10e8ffa115696ddf29c48440c5bae4 (patch)
treea156b9b64ef953463e97d3722e70f638a2efff0e /src/basic
parent1602b008531ba6e0c704588cb2643daef26b71d9 (diff)
strv: Add _cleanup_strv_free_erase_ and _cleanup_string_free_erase_
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/strv.c9
-rw-r--r--src/basic/strv.h4
-rw-r--r--src/basic/util.c9
-rw-r--r--src/basic/util.h5
4 files changed, 22 insertions, 5 deletions
diff --git a/src/basic/strv.c b/src/basic/strv.c
index b66c176487..501d022cb9 100644
--- a/src/basic/strv.c
+++ b/src/basic/strv.c
@@ -86,6 +86,15 @@ char **strv_free(char **l) {
return NULL;
}
+char **strv_free_erase(char **l) {
+ char **i;
+
+ STRV_FOREACH(i, l)
+ string_erase(*i);
+
+ return strv_free(l);
+}
+
char **strv_copy(char * const *l) {
char **r, **k;
diff --git a/src/basic/strv.h b/src/basic/strv.h
index e49f443835..a5dc696a87 100644
--- a/src/basic/strv.h
+++ b/src/basic/strv.h
@@ -35,6 +35,10 @@ char **strv_free(char **l);
DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free);
#define _cleanup_strv_free_ _cleanup_(strv_freep)
+char **strv_free_erase(char **l);
+DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free_erase);
+#define _cleanup_strv_free_erase_ _cleanup_(strv_free_erasep)
+
void strv_clear(char **l);
char **strv_copy(char * const *l);
diff --git a/src/basic/util.c b/src/basic/util.c
index f24db9796e..a14ed2e4cc 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -6817,9 +6817,10 @@ void string_erase(char *x) {
memory_erase(x, strlen(x));
}
-void strv_erase(char **l) {
- char **i;
+char *string_free_erase(char *s) {
+ if (!s)
+ return NULL;
- STRV_FOREACH(i, l)
- string_erase(*i);
+ string_erase(s);
+ return mfree(s);
}
diff --git a/src/basic/util.h b/src/basic/util.h
index b1c64675e0..4b1c5878c5 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -946,4 +946,7 @@ bool oom_score_adjust_is_valid(int oa);
#define memory_erase(p, l) memset((p), 'x', (l))
void string_erase(char *x);
-void strv_erase(char **l);
+
+char *string_free_erase(char *s);
+DEFINE_TRIVIAL_CLEANUP_FUNC(char *, string_free_erase);
+#define _cleanup_string_free_erase_ _cleanup_(string_free_erasep)