[systemd-devel] [PATCH 1/2] allover: remove unnecessary if() statements
Sami Kerola
kerolasa at iki.fi
Sun Jan 27 13:51:11 PST 2013
The coccicheck-0.2.4 detected unnecessary NULL checks. Almost all of
them were in format
type *example;
example = request_reservation();
if (!example)
return;
here_be_dragons;
if (d)
free(example);
where the later if is impossible to be false.
---
src/core/dbus.c | 3 +--
src/core/manager.c | 3 +--
src/journal/journal-vacuum.c | 4 +---
src/login/logind-acl.c | 3 +--
src/login/logind-user.c | 3 +--
src/login/sd-login.c | 3 +--
src/login/sysfs-show.c | 3 +--
src/readahead/readahead-common.c | 3 +--
src/shared/capability.c | 6 ++----
src/shared/cgroup-show.c | 4 +---
src/shared/install.c | 3 +--
src/shared/polkit.c | 3 +--
src/shared/util.c | 3 +--
src/tmpfiles/tmpfiles.c | 6 ++----
14 files changed, 16 insertions(+), 34 deletions(-)
diff --git a/src/core/dbus.c b/src/core/dbus.c
index 2a1c660..7a4d5d7 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -1474,6 +1474,5 @@ void bus_broadcast_finished(
}
finish:
- if (message)
- dbus_message_unref(message);
+ dbus_message_unref(message);
}
diff --git a/src/core/manager.c b/src/core/manager.c
index b538a9a..57170f2 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -2344,8 +2344,7 @@ void manager_run_generators(Manager *m) {
trim_generator_dir(m, &m->generator_unit_path_late);
finish:
- if (d)
- closedir(d);
+ closedir(d);
}
static void remove_generator_dir(Manager *m, char **generator) {
diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c
index 731f6c7..e71abcc 100644
--- a/src/journal/journal-vacuum.c
+++ b/src/journal/journal-vacuum.c
@@ -310,9 +310,7 @@ finish:
free(list[i].filename);
free(list);
-
- if (d)
- closedir(d);
+ closedir(d);
return r;
}
diff --git a/src/login/logind-acl.c b/src/login/logind-acl.c
index cb045a9..e33851d 100644
--- a/src/login/logind-acl.c
+++ b/src/login/logind-acl.c
@@ -241,8 +241,7 @@ int devnode_acl_all(struct udev *udev,
}
finish:
- if (e)
- udev_enumerate_unref(e);
+ udev_enumerate_unref(e);
return r;
}
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index b692b53..4ef7392 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -639,8 +639,7 @@ int user_kill(User *u, int signo) {
if (q != -EAGAIN && q != -ESRCH && q != -ENOENT)
r = q;
- if (pid_set)
- set_free(pid_set);
+ set_free(pid_set);
return r;
}
diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index 4bc51e7..9e162ce 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -699,8 +699,7 @@ _public_ int sd_get_uids(uid_t **users) {
}
finish:
- if (d)
- closedir(d);
+ closedir(d);
if (r >= 0) {
if (users)
diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c
index fc3af75..a2714b1 100644
--- a/src/login/sysfs-show.c
+++ b/src/login/sysfs-show.c
@@ -187,8 +187,7 @@ finish:
if (e)
udev_enumerate_unref(e);
- if (udev)
- udev_unref(udev);
+ udev_unref(udev);
return r;
}
diff --git a/src/readahead/readahead-common.c b/src/readahead/readahead-common.c
index 41aaff0..e8e4d45 100644
--- a/src/readahead/readahead-common.c
+++ b/src/readahead/readahead-common.c
@@ -165,8 +165,7 @@ finish:
if (udev_device)
udev_device_unref(udev_device);
- if (udev)
- udev_unref(udev);
+ udev_unref(udev);
return b;
}
diff --git a/src/shared/capability.c b/src/shared/capability.c
index 9b743e8..638a7b1 100644
--- a/src/shared/capability.c
+++ b/src/shared/capability.c
@@ -164,10 +164,8 @@ finish:
if (temp_cap)
cap_free(temp_cap);
- if (after_cap) {
- cap_set_proc(after_cap);
- cap_free(after_cap);
- }
+ cap_set_proc(after_cap);
+ cap_free(after_cap);
return r;
}
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index 2f2669f..9464dd2 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -158,9 +158,7 @@ static int show_cgroup_one_by_path(const char *path, const char *prefix, unsigne
finish:
free(pids);
-
- if (f)
- fclose(f);
+ fclose(f);
return r;
}
diff --git a/src/shared/install.c b/src/shared/install.c
index a9d75f3..7577761 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -958,8 +958,7 @@ static int install_info_add(
return 0;
fail:
- if (i)
- install_info_free(i);
+ install_info_free(i);
return r;
}
diff --git a/src/shared/polkit.c b/src/shared/polkit.c
index 8269445..be81e16 100644
--- a/src/shared/polkit.c
+++ b/src/shared/polkit.c
@@ -156,8 +156,7 @@ int verify_polkit(
r = -EPERM;
finish:
- if (m)
- dbus_message_unref(m);
+ dbus_message_unref(m);
if (reply)
dbus_message_unref(reply);
diff --git a/src/shared/util.c b/src/shared/util.c
index 969ef2b..377ddf4 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4683,8 +4683,7 @@ int get_files_in_directory(const char *path, char ***list) {
}
finish:
- if (d)
- closedir(d);
+ closedir(d);
if (r >= 0) {
if (list)
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index c2023f5..3383118 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -202,8 +202,7 @@ fail:
set_free_free(unix_sockets);
unix_sockets = NULL;
- if (f)
- fclose(f);
+ fclose(f);
}
static bool unix_socket_alive(const char *fn) {
@@ -907,8 +906,7 @@ static int clean_item_instance(Item *i, const char* instance) {
r = dir_cleanup(i, instance, d, &s, cutoff, s.st_dev, mountpoint, MAX_DEPTH, i->keep_first_level);
finish:
- if (d)
- closedir(d);
+ closedir(d);
return r;
}
--
1.8.1.1
More information about the systemd-devel
mailing list