chiark / gitweb /
Unifiy free() usage
authorSven Eden <yamakuzure@gmx.net>
Mon, 13 Mar 2017 08:20:24 +0000 (09:20 +0100)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:23:22 +0000 (10:23 +0100)
This commit substitutes all occurrences of
        free(foo);
        foo = NULL;
with
        foo = mfree(foo);

src/basic/strv.c
src/libelogind/sd-bus/bus-creds.c
src/libelogind/sd-bus/bus-message.c
src/libelogind/sd-bus/sd-bus.c
src/login/logind-dbus.c
src/login/logind-inhibit.c
src/login/logind-session.c
src/login/logind-user.c
src/shared/bus-util.c

index 9decbb4..dab34d8 100644 (file)
@@ -276,8 +276,7 @@ char **strv_split_newlines(const char *s) {
                 return l;
 
         if (isempty(l[n-1])) {
-                free(l[n-1]);
-                l[n-1] = NULL;
+                l[n-1] = mfree(l[n-1]);
         }
 
         return l;
index 7c763a2..4fccae5 100644 (file)
@@ -107,8 +107,7 @@ _public_ sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c) {
                         free(c->cgroup_root);
                         free(c->description);
 
-                        free(c->supplementary_gids);
-                        c->supplementary_gids = NULL;
+                        c->supplementary_gids = mfree(c->supplementary_gids);
 
                         strv_free(c->well_known_names);
                         c->well_known_names = NULL;
@@ -1049,8 +1048,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
                                 return r;
                 } else {
                         if (c->cmdline_size == 0) {
-                                free(c->cmdline);
-                                c->cmdline = NULL;
+                                c->cmdline = mfree(c->cmdline);
                         }
 
                         c->mask |= SD_BUS_CREDS_CMDLINE;
index 378d1af..36b8ebe 100644 (file)
@@ -113,8 +113,7 @@ static void message_reset_containers(sd_bus_message *m) {
                 free(m->containers[i].offsets);
         }
 
-        free(m->containers);
-        m->containers = NULL;
+        m->containers = mfree(m->containers);
 
         m->n_containers = m->containers_allocated = 0;
         m->root_container.index = 0;
index 2ccfacb..6acc9f3 100644 (file)
@@ -829,8 +829,7 @@ static int parse_container_unix_address(sd_bus *b, const char **p, char **guid)
                 b->machine = machine;
                 machine = NULL;
         } else {
-                free(b->machine);
-                b->machine = NULL;
+                b->machine = mfree(b->machine);
         }
 
         if (pid) {
@@ -889,8 +888,7 @@ static int parse_container_kernel_address(sd_bus *b, const char **p, char **guid
                 b->machine = machine;
                 machine = NULL;
         } else {
-                free(b->machine);
-                b->machine = NULL;
+                b->machine = mfree(b->machine);
         }
 
         if (pid) {
index 5dedbfc..800e2a5 100644 (file)
@@ -1998,8 +1998,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
         m->scheduled_shutdown_timeout_source = sd_event_source_unref(m->scheduled_shutdown_timeout_source);
         m->wall_message_timeout_source = sd_event_source_unref(m->wall_message_timeout_source);
         m->nologin_timeout_source = sd_event_source_unref(m->nologin_timeout_source);
-        free(m->scheduled_shutdown_type);
-        m->scheduled_shutdown_type = NULL;
+        m->scheduled_shutdown_type = mfree(m->scheduled_shutdown_type);
         m->scheduled_shutdown_timeout = 0;
 
         if (cancelled) {
index cfae186..0c9c1e5 100644 (file)
@@ -333,8 +333,7 @@ void inhibitor_remove_fifo(Inhibitor *i) {
 
         if (i->fifo_path) {
                 unlink(i->fifo_path);
-                free(i->fifo_path);
-                i->fifo_path = NULL;
+                i->fifo_path = mfree(i->fifo_path);
         }
 }
 
index c7033bd..bbfbeac 100644 (file)
@@ -984,8 +984,7 @@ static void session_remove_fifo(Session *s) {
 
         if (s->fifo_path) {
                 unlink(s->fifo_path);
-                free(s->fifo_path);
-                s->fifo_path = NULL;
+                s->fifo_path = mfree(s->fifo_path);
         }
 }
 
index e5833ef..63adc82 100644 (file)
@@ -590,8 +590,7 @@ static int user_remove_runtime_path(User *u) {
         if (r < 0)
                 log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path);
 
-        free(u->runtime_path);
-        u->runtime_path = NULL;
+        u->runtime_path = mfree(u->runtime_path);
 
         return r;
 }
index b72bb82..1e80ebc 100644 (file)
@@ -1904,11 +1904,9 @@ int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet) {
                         log_debug_errno(q, "Got result %s/%m for job %s", strna(d->result), strna(d->name));
                 }
 
-                free(d->name);
-                d->name = NULL;
+                d->name = mfree(d->name);
 
-                free(d->result);
-                d->result = NULL;
+                d->result = mfree(d->result);
         }
 
         return r;