]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
strv: add strv_free_free() to strv.c and make use of it
authorLennart Poettering <lennart@poettering.net>
Tue, 22 Sep 2015 23:01:26 +0000 (01:01 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 29 Sep 2015 19:08:37 +0000 (21:08 +0200)
Let's teach it a new trick, and make it return NULL.

src/basic/strv.c
src/basic/strv.h
src/core/main.c

index b9aef64b1586b78974800787d3ffbef2a2eb18ce..92f900936e44c4dee5975f6d6140e36fe83a5f93 100644 (file)
@@ -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;
+}
index f07da8cdf3b7965251ef851278cd4e68ba1c5058..713e91f8f8eecaea9fdca8ebd0835a0ef430a05a 100644 (file)
@@ -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);
index bc72a2b00b012e6bf6edc9de25a0078179f67b43..3fc6efa2913ea06a85baa2e655881981c9e074b7 100644 (file)
@@ -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();