]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: make use of the fact that strv_free() returns NULL
authorLennart Poettering <lennart@poettering.net>
Wed, 9 Sep 2015 21:05:10 +0000 (23:05 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 9 Sep 2015 21:05:58 +0000 (23:05 +0200)
Another Coccinelle patch.

coccinelle/strv_free.cocci [new file with mode: 0644]
src/core/dbus.c
src/core/execute.c
src/core/load-fragment.c
src/core/unit.c
src/libsystemd/sd-bus/bus-creds.c
src/resolve/resolved-link.c
src/shared/path-lookup.c

diff --git a/coccinelle/strv_free.cocci b/coccinelle/strv_free.cocci
new file mode 100644 (file)
index 0000000..0ad56f7
--- /dev/null
@@ -0,0 +1,27 @@
+@@
+expression p;
+@@
+- strv_free(p);
+- p = NULL;
++ p = strv_free(p);
+@@
+expression p;
+@@
+- if (p)
+-         strv_free(p);
+- p = NULL;
++ p = strv_free(p);
+@@
+expression p;
+@@
+- if (p) {
+-         strv_free(p);
+-         p = NULL;
+- }
++ p = strv_free(p);
+@@
+expression p;
+@@
+- if (p)
+-         strv_free(p);
++ strv_free(p);
index 0a2180c6a7e54d044008fd36534fd343af83006a..dcaf7cc835d7b271f92f602d9b5e1a1212e183b1 100644 (file)
@@ -1059,8 +1059,7 @@ void bus_done(Manager *m) {
         m->private_buses = NULL;
 
         m->subscribed = sd_bus_track_unref(m->subscribed);
-        strv_free(m->deserialized_subscribed);
-        m->deserialized_subscribed = NULL;
+        m->deserialized_subscribed = strv_free(m->deserialized_subscribed);
 
         if (m->private_listen_event_source)
                 m->private_listen_event_source = sd_event_source_unref(m->private_listen_event_source);
@@ -1191,8 +1190,7 @@ int bus_track_coldplug(Manager *m, sd_bus_track **t, char ***l) {
                 }
         }
 
-        strv_free(*l);
-        *l = NULL;
+        *l = strv_free(*l);
 
         return r;
 }
index 6abb0a5d5dbbc929ad6ae9e80a97326a0c1984c4..86c2a8067331824d307af8355b78508afc74ecb0 100644 (file)
@@ -1992,11 +1992,8 @@ void exec_context_done(ExecContext *c) {
 
         assert(c);
 
-        strv_free(c->environment);
-        c->environment = NULL;
-
-        strv_free(c->environment_files);
-        c->environment_files = NULL;
+        c->environment = strv_free(c->environment);
+        c->environment_files = strv_free(c->environment_files);
 
         for (l = 0; l < ELEMENTSOF(c->rlimit); l++)
                 c->rlimit[l] = mfree(c->rlimit[l]);
@@ -2008,8 +2005,7 @@ void exec_context_done(ExecContext *c) {
         c->user = mfree(c->user);
         c->group = mfree(c->group);
 
-        strv_free(c->supplementary_groups);
-        c->supplementary_groups = NULL;
+        c->supplementary_groups = strv_free(c->supplementary_groups);
 
         c->pam_name = mfree(c->pam_name);
 
@@ -2018,14 +2014,9 @@ void exec_context_done(ExecContext *c) {
                 c->capabilities = NULL;
         }
 
-        strv_free(c->read_only_dirs);
-        c->read_only_dirs = NULL;
-
-        strv_free(c->read_write_dirs);
-        c->read_write_dirs = NULL;
-
-        strv_free(c->inaccessible_dirs);
-        c->inaccessible_dirs = NULL;
+        c->read_only_dirs = strv_free(c->read_only_dirs);
+        c->read_write_dirs = strv_free(c->read_write_dirs);
+        c->inaccessible_dirs = strv_free(c->inaccessible_dirs);
 
         if (c->cpuset)
                 CPU_FREE(c->cpuset);
@@ -2043,8 +2034,7 @@ void exec_context_done(ExecContext *c) {
         set_free(c->address_families);
         c->address_families = NULL;
 
-        strv_free(c->runtime_directory);
-        c->runtime_directory = NULL;
+        c->runtime_directory = strv_free(c->runtime_directory);
 
         bus_endpoint_free(c->bus_endpoint);
         c->bus_endpoint = NULL;
@@ -2079,8 +2069,7 @@ void exec_command_done(ExecCommand *c) {
 
         c->path = mfree(c->path);
 
-        strv_free(c->argv);
-        c->argv = NULL;
+        c->argv = strv_free(c->argv);
 }
 
 void exec_command_done_array(ExecCommand *c, unsigned n) {
index b695c57da8e441acaf315e61e469e99d4a7e52dd..79dd3075c9691a3ed61f5a891bac47b9a08d1da7 100644 (file)
@@ -1888,8 +1888,7 @@ int config_parse_unit_env_file(const char *unit,
 
         if (isempty(rvalue)) {
                 /* Empty assignment frees the list */
-                strv_free(*env);
-                *env = NULL;
+                *env = strv_free(*env);
                 return 0;
         }
 
@@ -1937,8 +1936,7 @@ int config_parse_environ(const char *unit,
 
         if (isempty(rvalue)) {
                 /* Empty assignment resets the list */
-                strv_free(*env);
-                *env = NULL;
+                *env = strv_free(*env);
                 return 0;
         }
 
@@ -2245,8 +2243,7 @@ int config_parse_documentation(const char *unit,
 
         if (isempty(rvalue)) {
                 /* Empty assignment resets the list */
-                strv_free(u->documentation);
-                u->documentation = NULL;
+                u->documentation = strv_free(u->documentation);
                 return 0;
         }
 
@@ -3011,8 +3008,7 @@ int config_parse_runtime_directory(
 
         if (isempty(rvalue)) {
                 /* Empty assignment resets the list */
-                strv_free(*rt);
-                *rt = NULL;
+                *rt = strv_free(*rt);
                 return 0;
         }
 
@@ -3140,8 +3136,7 @@ int config_parse_namespace_path_strv(
 
         if (isempty(rvalue)) {
                 /* Empty assignment resets the list */
-                strv_free(*sv);
-                *sv = NULL;
+                *sv = strv_free(*sv);
                 return 0;
         }
 
index 24a6747b1085c1371d2e23e27bac0baf090325c2..563d7bf254fcf40db6903af178b0c5e1e37c298f 100644 (file)
@@ -445,8 +445,7 @@ static void unit_free_requires_mounts_for(Unit *u) {
                 }
         }
 
-        strv_free(u->requires_mounts_for);
-        u->requires_mounts_for = NULL;
+        u->requires_mounts_for = strv_free(u->requires_mounts_for);
 }
 
 static void unit_done(Unit *u) {
index 6826e2166545afc59e1977e686ade02b27d845aa..3e8cb0b7d0ded0cb1a5603f92860079a07ec01ac 100644 (file)
@@ -109,8 +109,7 @@ _public_ sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c) {
 
                         c->supplementary_gids = mfree(c->supplementary_gids);
 
-                        strv_free(c->well_known_names);
-                        c->well_known_names = NULL;
+                        c->well_known_names = strv_free(c->well_known_names);
 
                         bus_creds_done(c);
 
index 47f461a37d2ff2b31c82ca58cc5d5d69f4547b78..b9fd8e3dbcdba47f8d89365358398e652c1b4447 100644 (file)
@@ -238,8 +238,7 @@ static int link_update_domains(Link *l) {
         if (!l->unicast_scope)
                 return 0;
 
-        strv_free(l->unicast_scope->domains);
-        l->unicast_scope->domains = NULL;
+        l->unicast_scope->domains = strv_free(l->unicast_scope->domains);
 
         r = sd_network_link_get_domains(l->ifindex,
                                         &l->unicast_scope->domains);
index f6a127174ca61a408c572738825d4878fde58db0..d803bbe07e1cc68151218c4902e25ef1375edd3d 100644 (file)
@@ -333,8 +333,7 @@ int lookup_paths_init(
                 log_debug("Looking for unit files in (higher priority first):\n\t%s", t);
         } else {
                 log_debug("Ignoring unit files.");
-                strv_free(p->unit_path);
-                p->unit_path = NULL;
+                p->unit_path = strv_free(p->unit_path);
         }
 
         if (running_as == MANAGER_SYSTEM) {
@@ -390,8 +389,7 @@ int lookup_paths_init(
                         log_debug("Looking for SysV init scripts in:\n\t%s", t);
                 } else {
                         log_debug("Ignoring SysV init scripts.");
-                        strv_free(p->sysvinit_path);
-                        p->sysvinit_path = NULL;
+                        p->sysvinit_path = strv_free(p->sysvinit_path);
                 }
 
                 if (!strv_isempty(p->sysvrcnd_path)) {
@@ -403,8 +401,7 @@ int lookup_paths_init(
                         log_debug("Looking for SysV rcN.d links in:\n\t%s", t);
                 } else {
                         log_debug("Ignoring SysV rcN.d links.");
-                        strv_free(p->sysvrcnd_path);
-                        p->sysvrcnd_path = NULL;
+                        p->sysvrcnd_path = strv_free(p->sysvrcnd_path);
                 }
 #else
                 log_debug("SysV init scripts and rcN.d links support disabled");
@@ -417,8 +414,7 @@ int lookup_paths_init(
 void lookup_paths_free(LookupPaths *p) {
         assert(p);
 
-        strv_free(p->unit_path);
-        p->unit_path = NULL;
+        p->unit_path = strv_free(p->unit_path);
 
 #ifdef HAVE_SYSV_COMPAT
         strv_free(p->sysvinit_path);