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 9decbb4190c4282352900679fe01ce1c8db91a03..dab34d8e74ee91de78965975fa53ba479035521b 100644 (file)
@@ -276,8 +276,7 @@ char **strv_split_newlines(const char *s) {
                 return l;
 
         if (isempty(l[n-1])) {
                 return l;
 
         if (isempty(l[n-1])) {
-                free(l[n-1]);
-                l[n-1] = NULL;
+                l[n-1] = mfree(l[n-1]);
         }
 
         return l;
         }
 
         return l;
index 7c763a2e7e4f7806904fef1552a1e83fe2f567eb..4fccae5034406c277273df513602a4f625a79e17 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->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;
 
                         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) {
                                 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;
                         }
 
                         c->mask |= SD_BUS_CREDS_CMDLINE;
index 378d1af1a0e82e8d6d673adbb5bb3febcb43f8bb..36b8ebea0cca2db38b9e87bd89be9057446fff0c 100644 (file)
@@ -113,8 +113,7 @@ static void message_reset_containers(sd_bus_message *m) {
                 free(m->containers[i].offsets);
         }
 
                 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;
 
         m->n_containers = m->containers_allocated = 0;
         m->root_container.index = 0;
index 2ccfacbdfde48df05604075daa5f38f97f7aa443..6acc9f3860bc27473941c02f63aa9a401567cfb4 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 {
                 b->machine = machine;
                 machine = NULL;
         } else {
-                free(b->machine);
-                b->machine = NULL;
+                b->machine = mfree(b->machine);
         }
 
         if (pid) {
         }
 
         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 {
                 b->machine = machine;
                 machine = NULL;
         } else {
-                free(b->machine);
-                b->machine = NULL;
+                b->machine = mfree(b->machine);
         }
 
         if (pid) {
         }
 
         if (pid) {
index 5dedbfc907496513ca1919a1e537ae4925ef69f0..800e2a51b63185cfa6a0b7bb18ffd10a33fb5a45 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);
         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) {
         m->scheduled_shutdown_timeout = 0;
 
         if (cancelled) {
index cfae186edd615c5c8e4e3c799acca50f3aaa8c26..0c9c1e5e9795065e1ce4bd552cae76e281579b91 100644 (file)
@@ -333,8 +333,7 @@ void inhibitor_remove_fifo(Inhibitor *i) {
 
         if (i->fifo_path) {
                 unlink(i->fifo_path);
 
         if (i->fifo_path) {
                 unlink(i->fifo_path);
-                free(i->fifo_path);
-                i->fifo_path = NULL;
+                i->fifo_path = mfree(i->fifo_path);
         }
 }
 
         }
 }
 
index c7033bd18434b4e9fe6decfb901b2c7d5ca6d5e7..bbfbeac53e0081e0ffa303f97f5c214f17ec9e2b 100644 (file)
@@ -984,8 +984,7 @@ static void session_remove_fifo(Session *s) {
 
         if (s->fifo_path) {
                 unlink(s->fifo_path);
 
         if (s->fifo_path) {
                 unlink(s->fifo_path);
-                free(s->fifo_path);
-                s->fifo_path = NULL;
+                s->fifo_path = mfree(s->fifo_path);
         }
 }
 
         }
 }
 
index e5833ef50866fb75dde11ecd031a031358c3b7b1..63adc821080c9f4d9d12166c78f7bcda4205188c 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);
 
         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;
 }
 
         return r;
 }
index b72bb8278750eb8fa44d9574f6cb7481ec8e0ffb..1e80ebcf6cef918fc5eb73ef45f464dbe43feafc 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));
                 }
 
                         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;
         }
 
         return r;