diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/automount.c | 3 | ||||
-rw-r--r-- | src/core/busname.c | 3 | ||||
-rw-r--r-- | src/core/dbus-execute.c | 6 | ||||
-rw-r--r-- | src/core/device.c | 3 | ||||
-rw-r--r-- | src/core/execute.c | 63 | ||||
-rw-r--r-- | src/core/load-fragment.c | 15 | ||||
-rw-r--r-- | src/core/main.c | 6 | ||||
-rw-r--r-- | src/core/manager.c | 12 | ||||
-rw-r--r-- | src/core/mount.c | 3 | ||||
-rw-r--r-- | src/core/namespace.c | 3 | ||||
-rw-r--r-- | src/core/scope.c | 3 | ||||
-rw-r--r-- | src/core/service.c | 23 | ||||
-rw-r--r-- | src/core/shutdown.c | 3 | ||||
-rw-r--r-- | src/core/socket.c | 11 | ||||
-rw-r--r-- | src/core/swap.c | 17 | ||||
-rw-r--r-- | src/core/transaction.c | 10 |
16 files changed, 67 insertions, 117 deletions
diff --git a/src/core/automount.c b/src/core/automount.c index b8171ddad7..5bb61b95d3 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -127,8 +127,7 @@ static void automount_done(Unit *u) { unmount_autofs(a); - free(a->where); - a->where = NULL; + a->where = mfree(a->where); set_free(a->tokens); a->tokens = NULL; diff --git a/src/core/busname.c b/src/core/busname.c index d3c1282239..4020e9dd3c 100644 --- a/src/core/busname.c +++ b/src/core/busname.c @@ -95,8 +95,7 @@ static void busname_done(Unit *u) { assert(n); - free(n->name); - n->name = NULL; + n->name = mfree(n->name); busname_free_policy(n); busname_unwatch_control_pid(n); diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 3c98a0b186..ed55fcfca2 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -786,8 +786,7 @@ int bus_exec_context_set_transient_property( if (mode != UNIT_CHECK) { if (isempty(uu)) { - free(c->user); - c->user = NULL; + c->user = mfree(c->user); } else { char *t; @@ -814,8 +813,7 @@ int bus_exec_context_set_transient_property( if (mode != UNIT_CHECK) { if (isempty(gg)) { - free(c->group); - c->group = NULL; + c->group = mfree(c->group); } else { char *t; diff --git a/src/core/device.c b/src/core/device.c index 3f574b1832..7fdfacfddf 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -60,8 +60,7 @@ static void device_unset_sysfs(Device *d) { else hashmap_remove(devices, d->sysfs); - free(d->sysfs); - d->sysfs = NULL; + d->sysfs = mfree(d->sysfs); } static int device_set_sysfs(Device *d, const char *sysfs) { diff --git a/src/core/execute.c b/src/core/execute.c index 28eeeaad18..cd3592b847 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -122,7 +122,8 @@ static int shift_fds(int fds[], unsigned n_fds) { if (fds[i] == i+3) continue; - if ((nfd = fcntl(fds[i], F_DUPFD, i+3)) < 0) + nfd = fcntl(fds[i], F_DUPFD, i + 3); + if (nfd < 0) return -errno; safe_close(fds[i]); @@ -156,14 +157,16 @@ static int flags_fds(const int fds[], unsigned n_fds, bool nonblock) { for (i = 0; i < n_fds; i++) { - if ((r = fd_nonblock(fds[i], nonblock)) < 0) + r = fd_nonblock(fds[i], nonblock); + if (r < 0) return r; /* We unconditionally drop FD_CLOEXEC from the fds, * since after all we want to pass these fds to our * children */ - if ((r = fd_cloexec(fds[i], false)) < 0) + r = fd_cloexec(fds[i], false); + if (r < 0) return r; } @@ -315,7 +318,8 @@ static int open_terminal_as(const char *path, mode_t mode, int nfd) { assert(path); assert(nfd >= 0); - if ((fd = open_terminal(path, mode | O_NOCTTY)) < 0) + fd = open_terminal(path, mode | O_NOCTTY); + if (fd < 0) return fd; if (fd != nfd) { @@ -629,7 +633,8 @@ static int enforce_groups(const ExecContext *context, const char *username, gid_ if (context->group) { const char *g = context->group; - if ((r = get_group_creds(&g, &gid)) < 0) + r = get_group_creds(&g, &gid); + if (r < 0) return r; } @@ -658,7 +663,8 @@ static int enforce_groups(const ExecContext *context, const char *username, gid_ return -ENOMEM; if (keep_groups) { - if ((k = getgroups(ngroups_max, gids)) < 0) { + k = getgroups(ngroups_max, gids); + if (k < 0) { free(gids); return -errno; } @@ -922,8 +928,7 @@ fail: log_error("PAM failed: %s", pam_strerror(handle, pam_code)); err = -EPERM; /* PAM errors do not map to errno */ } else { - log_error_errno(errno, "PAM failed: %m"); - err = -errno; + err = log_error_errno(errno, "PAM failed: %m"); } if (handle) { @@ -1994,32 +1999,20 @@ void exec_context_done(ExecContext *c) { c->environment_files = NULL; for (l = 0; l < ELEMENTSOF(c->rlimit); l++) { - free(c->rlimit[l]); - c->rlimit[l] = NULL; + c->rlimit[l] = mfree(c->rlimit[l]); } - free(c->working_directory); - c->working_directory = NULL; - free(c->root_directory); - c->root_directory = NULL; - - free(c->tty_path); - c->tty_path = NULL; - - free(c->syslog_identifier); - c->syslog_identifier = NULL; - - free(c->user); - c->user = NULL; - - free(c->group); - c->group = NULL; + c->working_directory = mfree(c->working_directory); + c->root_directory = mfree(c->root_directory); + c->tty_path = mfree(c->tty_path); + c->syslog_identifier = mfree(c->syslog_identifier); + c->user = mfree(c->user); + c->group = mfree(c->group); strv_free(c->supplementary_groups); c->supplementary_groups = NULL; - free(c->pam_name); - c->pam_name = NULL; + c->pam_name = mfree(c->pam_name); if (c->capabilities) { cap_free(c->capabilities); @@ -2038,14 +2031,9 @@ void exec_context_done(ExecContext *c) { if (c->cpuset) CPU_FREE(c->cpuset); - free(c->utmp_id); - c->utmp_id = NULL; - - free(c->selinux_context); - c->selinux_context = NULL; - - free(c->apparmor_profile); - c->apparmor_profile = NULL; + c->utmp_id = mfree(c->utmp_id); + c->selinux_context = mfree(c->selinux_context); + c->apparmor_profile = mfree(c->apparmor_profile); set_free(c->syscall_filter); c->syscall_filter = NULL; @@ -2090,8 +2078,7 @@ int exec_context_destroy_runtime_directory(ExecContext *c, const char *runtime_p void exec_command_done(ExecCommand *c) { assert(c); - free(c->path); - c->path = NULL; + c->path = mfree(c->path); strv_free(c->argv); c->argv = NULL; diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 542bf8eb26..b695c57da8 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -1215,8 +1215,7 @@ int config_parse_exec_selinux_context( assert(data); if (isempty(rvalue)) { - free(c->selinux_context); - c->selinux_context = NULL; + c->selinux_context = mfree(c->selinux_context); c->selinux_context_ignore = false; return 0; } @@ -1265,8 +1264,7 @@ int config_parse_exec_apparmor_profile( assert(data); if (isempty(rvalue)) { - free(c->apparmor_profile); - c->apparmor_profile = NULL; + c->apparmor_profile = mfree(c->apparmor_profile); c->apparmor_profile_ignore = false; return 0; } @@ -1315,8 +1313,7 @@ int config_parse_exec_smack_process_label( assert(data); if (isempty(rvalue)) { - free(c->smack_process_label); - c->smack_process_label = NULL; + c->smack_process_label = mfree(c->smack_process_label); c->smack_process_label_ignore = false; return 0; } @@ -3571,13 +3568,11 @@ int unit_load_fragment(Unit *u) { if (r < 0) return r; - if (u->load_state == UNIT_STUB) { + if (u->load_state == UNIT_STUB) /* Hmm, this didn't work? Then let's get rid * of the fragment path stored for us, so that * we don't point to an invalid location. */ - free(u->fragment_path); - u->fragment_path = NULL; - } + u->fragment_path = mfree(u->fragment_path); } /* Look for a template */ diff --git a/src/core/main.c b/src/core/main.c index fe8f1924bd..9aaf244e71 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1204,12 +1204,11 @@ static int status_welcome(void) { "PRETTY_NAME", &pretty_name, "ANSI_COLOR", &ansi_color, NULL); - if (r == -ENOENT) { + if (r == -ENOENT) r = parse_env_file("/usr/lib/os-release", NEWLINE, "PRETTY_NAME", &pretty_name, "ANSI_COLOR", &ansi_color, NULL); - } if (r < 0 && r != -ENOENT) log_warning_errno(r, "Failed to read os-release file: %m"); @@ -1843,8 +1842,7 @@ finish: m = manager_free(m); for (j = 0; j < ELEMENTSOF(arg_default_rlimit); j++) { - free(arg_default_rlimit[j]); - arg_default_rlimit[j] = NULL; + arg_default_rlimit[j] = mfree(arg_default_rlimit[j]); } arg_default_unit = mfree(arg_default_unit); diff --git a/src/core/manager.c b/src/core/manager.c index 56f2c92feb..d918007bb8 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -674,8 +674,7 @@ static int manager_setup_notify(Manager *m) { static const int one = 1; /* First free all secondary fields */ - free(m->notify_socket); - m->notify_socket = NULL; + m->notify_socket = mfree(m->notify_socket); m->notify_event_source = sd_event_source_unref(m->notify_event_source); fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); @@ -2793,10 +2792,8 @@ static void trim_generator_dir(Manager *m, char **generator) { if (!*generator) return; - if (rmdir(*generator) >= 0) { - free(*generator); - *generator = NULL; - } + if (rmdir(*generator) >= 0) + *generator = mfree(*generator); return; } @@ -2866,8 +2863,7 @@ static void remove_generator_dir(Manager *m, char **generator) { strv_remove(m->lookup_paths.unit_path, *generator); (void) rm_rf(*generator, REMOVE_ROOT); - free(*generator); - *generator = NULL; + *generator = mfree(*generator); } static void manager_undo_generators(Manager *m) { diff --git a/src/core/mount.c b/src/core/mount.c index 2b81d17b9c..83746ca412 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -203,8 +203,7 @@ static void mount_done(Unit *u) { assert(m); - free(m->where); - m->where = NULL; + m->where = mfree(m->where); mount_parameters_done(&m->parameters_proc_self_mountinfo); mount_parameters_done(&m->parameters_fragment); diff --git a/src/core/namespace.c b/src/core/namespace.c index 045321e1d4..0b85b859fa 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -288,8 +288,7 @@ static int mount_kdbus(BindMount *m) { /* create a new /dev/null dev node copy so we have some fodder to * bind-mount the custom endpoint over. */ if (stat("/dev/null", &st) < 0) { - log_error_errno(errno, "Failed to stat /dev/null: %m"); - r = -errno; + r = log_error_errno(errno, "Failed to stat /dev/null: %m"); goto fail; } diff --git a/src/core/scope.c b/src/core/scope.c index 35cf0621be..98395becfd 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -476,8 +476,7 @@ int scope_abandon(Scope *s) { if (!IN_SET(s->state, SCOPE_RUNNING, SCOPE_ABANDONED)) return -ESTALE; - free(s->controller); - s->controller = NULL; + s->controller = mfree(s->controller); /* The client is no longer watching the remaining processes, * so let's step in here, under the assumption that the diff --git a/src/core/service.c b/src/core/service.c index 292fe50de8..e396dbe213 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -142,8 +142,7 @@ static void service_unwatch_pid_file(Service *s) { log_unit_debug(UNIT(s), "Stopping watch for PID file %s", s->pid_file_pathspec->path); path_spec_unwatch(s->pid_file_pathspec); path_spec_done(s->pid_file_pathspec); - free(s->pid_file_pathspec); - s->pid_file_pathspec = NULL; + s->pid_file_pathspec = mfree(s->pid_file_pathspec); } static int service_set_main_pid(Service *s, pid_t pid) { @@ -287,14 +286,9 @@ static void service_done(Unit *u) { assert(s); - free(s->pid_file); - s->pid_file = NULL; - - free(s->status_text); - s->status_text = NULL; - - free(s->reboot_arg); - s->reboot_arg = NULL; + s->pid_file = mfree(s->pid_file); + s->status_text = mfree(s->status_text); + s->reboot_arg = mfree(s->reboot_arg); s->exec_runtime = exec_runtime_unref(s->exec_runtime); exec_command_free_array(s->exec_command, _SERVICE_EXEC_COMMAND_MAX); @@ -313,8 +307,7 @@ static void service_done(Unit *u) { if (s->bus_name) { unit_unwatch_bus_name(u, s->bus_name); - free(s->bus_name); - s->bus_name = NULL; + s->bus_name = mfree(s->bus_name); } s->bus_endpoint_fd = safe_close(s->bus_endpoint_fd); @@ -702,13 +695,12 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) { fprintf(f, "%sStatus Text: %s\n", prefix, s->status_text); - if (s->n_fd_store_max > 0) { + if (s->n_fd_store_max > 0) fprintf(f, "%sFile Descriptor Store Max: %u\n" "%sFile Descriptor Store Current: %u\n", prefix, s->n_fd_store_max, prefix, s->n_fd_store); - } } static int service_load_pid_file(Service *s, bool may_warn) { @@ -1939,8 +1931,7 @@ static int service_start(Unit *u) { s->forbid_restart = false; s->reset_cpu_usage = true; - free(s->status_text); - s->status_text = NULL; + s->status_text = mfree(s->status_text); s->status_errno = 0; s->notify_state = NOTIFY_UNKNOWN; diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 8a6fd25f31..8cc6efc5b8 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -404,8 +404,7 @@ int main(int argc, char *argv[]) { exit(0); } - log_error_errno(errno, "Failed to invoke reboot(): %m"); - r = -errno; + r = log_error_errno(errno, "Failed to invoke reboot(): %m"); error: log_emergency_errno(r, "Critical error while doing system shutdown: %m"); diff --git a/src/core/socket.c b/src/core/socket.c index 1014fad626..9db42a0333 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -135,11 +135,8 @@ static void socket_done(Unit *u) { unit_ref_unset(&s->service); - free(s->tcp_congestion); - s->tcp_congestion = NULL; - - free(s->bind_to_device); - s->bind_to_device = NULL; + s->tcp_congestion = mfree(s->tcp_congestion); + s->bind_to_device = mfree(s->bind_to_device); free(s->smack); free(s->smack_ip_in); @@ -985,7 +982,9 @@ static int fifo_address_create( goto fail; } - if ((fd = open(path, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW)) < 0) { + fd = open(path, + O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK | O_NOFOLLOW); + if (fd < 0) { r = -errno; goto fail; } diff --git a/src/core/swap.c b/src/core/swap.c index 2f462e339d..a26bc58cfc 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -59,8 +59,7 @@ static void swap_unset_proc_swaps(Swap *s) { if (!s->from_proc_swaps) return; - free(s->parameters_proc_swaps.what); - s->parameters_proc_swaps.what = NULL; + s->parameters_proc_swaps.what = mfree(s->parameters_proc_swaps.what); s->from_proc_swaps = false; } @@ -87,8 +86,7 @@ static int swap_set_devnode(Swap *s, const char *devnode) { else hashmap_remove(swaps, s->devnode); - free(s->devnode); - s->devnode = NULL; + s->devnode = mfree(s->devnode); } if (devnode) { @@ -141,14 +139,9 @@ static void swap_done(Unit *u) { swap_unset_proc_swaps(s); swap_set_devnode(s, NULL); - free(s->what); - s->what = NULL; - - free(s->parameters_fragment.what); - s->parameters_fragment.what = NULL; - - free(s->parameters_fragment.options); - s->parameters_fragment.options = NULL; + s->what = mfree(s->what); + s->parameters_fragment.what = mfree(s->parameters_fragment.what); + s->parameters_fragment.options = mfree(s->parameters_fragment.options); s->exec_runtime = exec_runtime_unref(s->exec_runtime); exec_command_done_array(s->exec_command, _SWAP_EXEC_COMMAND_MAX); diff --git a/src/core/transaction.c b/src/core/transaction.c index 090103fbda..b8f69ec6f3 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -380,12 +380,10 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi "Found dependency on %s/%s", k->unit->id, job_type_to_string(k->type)); - if (!delete && hashmap_get(tr->jobs, k->unit) && - !unit_matters_to_anchor(k->unit, k)) { + if (!delete && hashmap_get(tr->jobs, k->unit) && !unit_matters_to_anchor(k->unit, k)) /* Ok, we can drop this one, so let's * do so. */ delete = k; - } /* Check if this in fact was the beginning of * the cycle */ @@ -464,9 +462,11 @@ static int transaction_verify_order(Transaction *tr, unsigned *generation, sd_bu g = (*generation)++; - HASHMAP_FOREACH(j, tr->jobs, i) - if ((r = transaction_verify_order_one(tr, j, NULL, g, e)) < 0) + HASHMAP_FOREACH(j, tr->jobs, i) { + r = transaction_verify_order_one(tr, j, NULL, g, e); + if (r < 0) return r; + } return 0; } |