From fe382237cad0ade50d38075e0bf948ce07618461 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 23 Sep 2015 01:01:26 +0200 Subject: [PATCH] strv: add strv_free_free() to strv.c and make use of it Let's teach it a new trick, and make it return NULL. --- src/basic/strv.c | 13 +++++++++++++ src/basic/strv.h | 2 ++ src/core/main.c | 41 +++++++++++++---------------------------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/basic/strv.c b/src/basic/strv.c index b9aef64..92f9009 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -720,3 +720,16 @@ bool strv_fnmatch(char* const* patterns, const char *s, int flags) { return false; } + +char ***strv_free_free(char ***l) { + char ***i; + + if (!l) + return NULL; + + for (i = l; *i; i++) + strv_free(*i); + + free(l); + return NULL; +} diff --git a/src/basic/strv.h b/src/basic/strv.h index f07da8c..713e91f 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -154,3 +154,5 @@ static inline bool strv_fnmatch_or_empty(char* const* patterns, const char *s, i return strv_isempty(patterns) || strv_fnmatch(patterns, s, flags); } + +char ***strv_free_free(char ***l); diff --git a/src/core/main.c b/src/core/main.c index bc72a2b..3fc6efa 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -478,23 +478,6 @@ static int config_parse_show_status( return 0; } -static void strv_free_free(char ***l) { - char ***i; - - if (!l) - return; - - for (i = l; *i; i++) - strv_free(*i); - - free(l); -} - -static void free_join_controllers(void) { - strv_free_free(arg_join_controllers); - arg_join_controllers = NULL; -} - static int config_parse_join_controllers(const char *unit, const char *filename, unsigned line, @@ -513,7 +496,7 @@ static int config_parse_join_controllers(const char *unit, assert(lvalue); assert(rvalue); - free_join_controllers(); + arg_join_controllers = strv_free_free(arg_join_controllers); for (;;) { _cleanup_free_ char *word = NULL; @@ -1116,15 +1099,19 @@ static int initialize_join_controllers(void) { return -ENOMEM; arg_join_controllers[0] = strv_new("cpu", "cpuacct", NULL); - arg_join_controllers[1] = strv_new("net_cls", "net_prio", NULL); - arg_join_controllers[2] = NULL; + if (!arg_join_controllers[0]) + goto oom; - if (!arg_join_controllers[0] || !arg_join_controllers[1]) { - free_join_controllers(); - return -ENOMEM; - } + arg_join_controllers[1] = strv_new("net_cls", "net_prio", NULL); + if (!arg_join_controllers[1]) + goto oom; + arg_join_controllers[2] = NULL; return 0; + +oom: + arg_join_controllers = strv_free_free(arg_join_controllers); + return -ENOMEM; } static int enforce_syscall_archs(Set *archs) { @@ -1813,17 +1800,15 @@ finish: arg_shutdown_watchdog = m->shutdown_watchdog; shutdown_exit_code = m->return_value; } + m = manager_free(m); for (j = 0; j < ELEMENTSOF(arg_default_rlimit); j++) arg_default_rlimit[j] = mfree(arg_default_rlimit[j]); arg_default_unit = mfree(arg_default_unit); - - free_join_controllers(); - + arg_join_controllers = strv_free_free(arg_join_controllers); arg_default_environment = strv_free(arg_default_environment); - arg_syscall_archs = set_free(arg_syscall_archs); mac_selinux_finish(); -- 2.7.4