From 8ea913b2eaadbd92e069ea6b71cc5f5df409decf Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 23 Sep 2011 01:43:28 +0200 Subject: [PATCH] coverity: fix a couple of bugs found by coverity --- src/binfmt.c | 2 +- src/conf-parser.c | 2 +- src/install.c | 1 - src/load-fragment.c | 1 + src/localed.c | 3 +++ src/logind-dbus.c | 4 ++++ src/modules-load.c | 1 - src/path.c | 2 +- src/sd-login.c | 4 ++++ src/service.c | 2 +- src/socket.c | 2 +- src/strv.c | 17 ++++++++++++----- src/systemctl.c | 1 + src/timedated.c | 2 +- src/util.c | 5 +++++ 15 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/binfmt.c b/src/binfmt.c index 552d8cc2..e8d65243 100644 --- a/src/binfmt.c +++ b/src/binfmt.c @@ -33,7 +33,7 @@ #include "util.h" static int delete_rule(const char *rule) { - char *x, *fn, *e; + char *x, *fn = NULL, *e; int r; assert(rule[0]); diff --git a/src/conf-parser.c b/src/conf-parser.c index 3bb430e3..a71dcd0d 100644 --- a/src/conf-parser.c +++ b/src/conf-parser.c @@ -314,7 +314,7 @@ int config_parse( continuation = c; else { continuation = strdup(l); - if (!c) { + if (!continuation) { r = -ENOMEM; goto finish; } diff --git a/src/install.c b/src/install.c index 74439735..53dd26fd 100644 --- a/src/install.c +++ b/src/install.c @@ -479,7 +479,6 @@ static int find_symlinks_fd( t = path_make_absolute(name, config_path); if (!t) { free(p); - free(dest); r = -ENOMEM; break; } diff --git a/src/load-fragment.c b/src/load-fragment.c index c7d2da34..12079c64 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -554,6 +554,7 @@ int config_parse_exec( if (!n[0]) { log_error("[%s:%u] Invalid command line, ignoring: %s", filename, line, rvalue); strv_free(n); + free(path); return 0; } diff --git a/src/localed.c b/src/localed.c index f652110d..fbb5a41d 100644 --- a/src/localed.c +++ b/src/localed.c @@ -215,6 +215,7 @@ static int write_data(void) { } if (strv_isempty(l)) { + strv_free(l); if (unlink("/etc/locale.conf") < 0) return errno == ENOENT ? 0 : -errno; @@ -459,6 +460,8 @@ static DBusHandlerResult locale_message_handler( } } + strv_free(l); + for (p = 0; p < _PROP_MAX; p++) { if (passed[p]) continue; diff --git a/src/logind-dbus.c b/src/logind-dbus.c index b8f7d671..b33a096f 100644 --- a/src/logind-dbus.c +++ b/src/logind-dbus.c @@ -381,6 +381,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess session = hashmap_get(m->sessions, id); if (session) { + free(id); fifo_fd = session_create_fifo(session); if (fifo_fd < 0) { @@ -421,6 +422,9 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess close_nointr_nofail(fifo_fd); *_reply = reply; + strv_free(controllers); + strv_free(reset_controllers); + return 0; } diff --git a/src/modules-load.c b/src/modules-load.c index 17b5e0bf..8dd98f73 100644 --- a/src/modules-load.c +++ b/src/modules-load.c @@ -77,7 +77,6 @@ int main(int argc, char *argv[]) { continue; log_error("Failed to open %s: %m", *fn); - free(fn); r = EXIT_FAILURE; continue; } diff --git a/src/path.c b/src/path.c index 1d4aa217..f15c9214 100644 --- a/src/path.c +++ b/src/path.c @@ -563,7 +563,7 @@ static void path_fd_event(Unit *u, int fd, uint32_t events, Watch *w) { assert(l > 0); if (!(buf = malloc(l))) { - log_error("Failed to allocate buffer: %s", strerror(-ENOMEM)); + log_error("Failed to allocate buffer: %s", strerror(ENOMEM)); goto fail; } diff --git a/src/sd-login.c b/src/sd-login.c index 2489d78c..b670d182 100644 --- a/src/sd-login.c +++ b/src/sd-login.c @@ -499,6 +499,7 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui if (!k) { free(t); free(b); + strv_free(a); return -ENOMEM; } @@ -574,6 +575,9 @@ _public_ int sd_get_uids(uid_t **users) { uid_t *l = NULL; d = opendir("/run/systemd/users/"); + if (!d) + return -errno; + for (;;) { struct dirent buffer, *de; int k; diff --git a/src/service.c b/src/service.c index 2b45ecb7..2ae8785a 100644 --- a/src/service.c +++ b/src/service.c @@ -3115,7 +3115,7 @@ static int service_enumerate(Manager *m) { free(fpath); fpath = join(path, "/", de->d_name, NULL); - if (!path) { + if (!fpath) { r = -ENOMEM; goto finish; } diff --git a/src/socket.c b/src/socket.c index 572e6220..a1b451eb 100644 --- a/src/socket.c +++ b/src/socket.c @@ -844,7 +844,7 @@ static int mq_address_create( fd = mq_open(path, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_CREAT, mq_mode, attr); umask(old_mask); - if (fd < 0 && errno != EEXIST) { + if (fd < 0) { r = -errno; goto fail; } diff --git a/src/strv.c b/src/strv.c index 92851b22..640ae3f0 100644 --- a/src/strv.c +++ b/src/strv.c @@ -201,12 +201,19 @@ char **strv_merge_concat(char **a, char **b, const char *suffix) { if (!(r = new(char*, strv_length(a)+strv_length(b)+1))) return NULL; - for (k = r; *a; k++, a++) - if (!(*k = strdup(*a))) - goto fail; - for (; *b; k++, b++) - if (!(*k = strappend(*b, suffix))) + k = r; + if (a) + for (; *a; k++, a++) { + *k = strdup(*a); + if (!*k) + goto fail; + } + + for (; *b; k++, b++) { + *k = strappend(*b, suffix); + if (!*k) goto fail; + } *k = NULL; return r; diff --git a/src/systemctl.c b/src/systemctl.c index 7caeb6dd..e85a2fd4 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -608,6 +608,7 @@ static int list_unit_files(DBusConnection *bus, char **args) { r = unit_file_get_list(arg_scope, arg_root, h); if (r < 0) { + unit_file_list_free(h); log_error("Failed to get unit file list: %s", strerror(-r)); return r; } diff --git a/src/timedated.c b/src/timedated.c index 66e50a68..f6fe2d83 100644 --- a/src/timedated.c +++ b/src/timedated.c @@ -246,7 +246,7 @@ static int write_data_local_rtc(void) { p++; e = strchr(p, '\n'); - if (!p) { + if (!e) { free(s); return -EIO; } diff --git a/src/util.c b/src/util.c index 6033aa05..6a9fffbf 100644 --- a/src/util.c +++ b/src/util.c @@ -5529,6 +5529,9 @@ int get_files_in_directory(const char *path, char ***list) { * number */ d = opendir(path); + if (!d) + return -errno; + for (;;) { struct dirent buffer, *de; int k; @@ -5629,6 +5632,8 @@ char *join(const char *x, ...) { p = stpcpy(p, t); } + + va_end(ap); } else r[0] = 0; -- 2.39.5