summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-09-08 18:43:11 +0200
committerLennart Poettering <lennart@poettering.net>2015-09-09 08:19:27 +0200
commita1e58e8ee1c84b633d6d6d651d5328d4dd4eba5b (patch)
tree2c5288c0e505c561c779ea13b4d99e8101803ca2 /src/core
parentda323858ef34a0216aa96f4089810053c90f09ce (diff)
tree-wide: use coccinelle to patch a lot of code to use mfree()
This replaces this: free(p); p = NULL; by this: p = mfree(p); Change generated using coccinelle. Semantic patch is added to the sources.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/automount.c3
-rw-r--r--src/core/busname.c3
-rw-r--r--src/core/dbus-execute.c6
-rw-r--r--src/core/device.c3
-rw-r--r--src/core/execute.c42
-rw-r--r--src/core/load-fragment.c12
-rw-r--r--src/core/main.c3
-rw-r--r--src/core/manager.c9
-rw-r--r--src/core/mount.c3
-rw-r--r--src/core/scope.c3
-rw-r--r--src/core/service.c20
-rw-r--r--src/core/socket.c7
-rw-r--r--src/core/swap.c17
13 files changed, 40 insertions, 91 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..de5c16bd76 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -1994,32 +1994,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 +2026,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 +2073,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..0299fe7603 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;
}
@@ -3575,8 +3572,7 @@ int unit_load_fragment(Unit *u) {
/* 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);
}
}
diff --git a/src/core/main.c b/src/core/main.c
index fe8f1924bd..091af6a9df 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1843,8 +1843,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..cd0513fd69 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);
@@ -2794,8 +2793,7 @@ static void trim_generator_dir(Manager *m, char **generator) {
return;
if (rmdir(*generator) >= 0) {
- free(*generator);
- *generator = NULL;
+ *generator = mfree(*generator);
}
return;
@@ -2866,8 +2864,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/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..1cf1fcffdc 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);
@@ -1939,8 +1932,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/socket.c b/src/core/socket.c
index 1014fad626..7d3d5eb78a 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);
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);