[systemd-commits] 2 commits - src/binfmt.c src/conf-parser.c src/dbus-manager.c src/hostnamed.c src/install.c src/load-fragment.c src/localed.c src/loginctl.c src/logind-dbus.c src/modules-load.c src/nspawn.c src/path.c src/sd-login.c src/service.c src/socket.c src/strv.c src/systemctl.c src/timedated.c src/util.c
Lennart Poettering
lennart at kemper.freedesktop.org
Thu Sep 22 16:45:42 PDT 2011
src/binfmt.c | 2 +-
src/conf-parser.c | 2 +-
src/dbus-manager.c | 2 +-
src/hostnamed.c | 2 +-
src/install.c | 3 +--
src/load-fragment.c | 1 +
src/localed.c | 3 +++
src/loginctl.c | 48 ++++++++++++++++++++----------------------------
src/logind-dbus.c | 4 ++++
src/modules-load.c | 1 -
src/nspawn.c | 6 ++++--
src/path.c | 2 +-
src/sd-login.c | 4 ++++
src/service.c | 2 +-
src/socket.c | 2 +-
src/strv.c | 26 ++++++++++++++++++--------
src/systemctl.c | 21 +++++++++------------
src/timedated.c | 2 +-
src/util.c | 13 ++++++-------
19 files changed, 78 insertions(+), 68 deletions(-)
New commits:
commit f8440af5febb18ddfd2bc7a94b771284f0b7b310
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Sep 23 01:44:36 2011 +0200
coverity: change a few things so that coverity doesn't show so many false positives
diff --git a/src/dbus-manager.c b/src/dbus-manager.c
index 822189b..7b68156 100644
--- a/src/dbus-manager.c
+++ b/src/dbus-manager.c
@@ -300,7 +300,7 @@ static int bus_manager_append_tainted(DBusMessageIter *i, const char *property,
free(p);
if (access("/proc/cgroups", F_OK) < 0)
- e = stpcpy(e, "cgroups-missing ");
+ stpcpy(e, "cgroups-missing ");
t = strstrip(buf);
diff --git a/src/hostnamed.c b/src/hostnamed.c
index 0db78c0..b47f227 100644
--- a/src/hostnamed.c
+++ b/src/hostnamed.c
@@ -233,7 +233,7 @@ static int write_data_other(void) {
assert(name[p]);
if (isempty(data[p])) {
- l = strv_env_unset(l, name[p]);
+ strv_env_unset(l, name[p]);
continue;
}
diff --git a/src/install.c b/src/install.c
index 53dd26f..cfbd50e 100644
--- a/src/install.c
+++ b/src/install.c
@@ -1904,7 +1904,7 @@ int unit_file_get_list(
} else if (r > 0) {
f->state = UNIT_FILE_DISABLED;
goto found;
- } else if (r == 0) {
+ } else {
f->state = UNIT_FILE_STATIC;
goto found;
}
diff --git a/src/loginctl.c b/src/loginctl.c
index 53058d0..ba8020d 100644
--- a/src/loginctl.c
+++ b/src/loginctl.c
@@ -64,6 +64,8 @@ static bool on_tty(void) {
}
static void pager_open_if_enabled(void) {
+
+ /* Cache result before we open the pager */
on_tty();
if (!arg_no_pager)
@@ -1146,7 +1148,7 @@ finish:
}
static int activate(DBusConnection *bus, char **args, unsigned n) {
- DBusMessage *m = NULL, *reply = NULL;
+ DBusMessage *m = NULL;
int ret = 0;
DBusError error;
unsigned i;
@@ -1157,6 +1159,8 @@ static int activate(DBusConnection *bus, char **args, unsigned n) {
dbus_error_init(&error);
for (i = 1; i < n; i++) {
+ DBusMessage *reply;
+
m = dbus_message_new_method_call(
"org.freedesktop.login1",
"/org/freedesktop/login1",
@@ -1195,16 +1199,13 @@ finish:
if (m)
dbus_message_unref(m);
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return ret;
}
static int kill_session(DBusConnection *bus, char **args, unsigned n) {
- DBusMessage *m = NULL, *reply = NULL;
+ DBusMessage *m = NULL;
int ret = 0;
DBusError error;
unsigned i;
@@ -1218,6 +1219,8 @@ static int kill_session(DBusConnection *bus, char **args, unsigned n) {
arg_kill_who = "all";
for (i = 1; i < n; i++) {
+ DBusMessage *reply;
+
m = dbus_message_new_method_call(
"org.freedesktop.login1",
"/org/freedesktop/login1",
@@ -1255,16 +1258,13 @@ finish:
if (m)
dbus_message_unref(m);
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return ret;
}
static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
- DBusMessage *m = NULL, *reply = NULL;
+ DBusMessage *m = NULL;
int ret = 0;
DBusError error;
unsigned i;
@@ -1278,6 +1278,7 @@ static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
b = streq(args[0], "enable-linger");
for (i = 1; i < n; i++) {
+ DBusMessage *reply;
uint32_t u;
uid_t uid;
@@ -1327,16 +1328,13 @@ finish:
if (m)
dbus_message_unref(m);
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return ret;
}
static int terminate_user(DBusConnection *bus, char **args, unsigned n) {
- DBusMessage *m = NULL, *reply = NULL;
+ DBusMessage *m = NULL;
int ret = 0;
DBusError error;
unsigned i;
@@ -1349,6 +1347,7 @@ static int terminate_user(DBusConnection *bus, char **args, unsigned n) {
for (i = 1; i < n; i++) {
uint32_t u;
uid_t uid;
+ DBusMessage *reply;
m = dbus_message_new_method_call(
"org.freedesktop.login1",
@@ -1394,16 +1393,13 @@ finish:
if (m)
dbus_message_unref(m);
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return ret;
}
static int kill_user(DBusConnection *bus, char **args, unsigned n) {
- DBusMessage *m = NULL, *reply = NULL;
+ DBusMessage *m = NULL;
int ret = 0;
DBusError error;
unsigned i;
@@ -1417,6 +1413,7 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) {
arg_kill_who = "all";
for (i = 1; i < n; i++) {
+ DBusMessage *reply;
uid_t uid;
uint32_t u;
@@ -1465,16 +1462,13 @@ finish:
if (m)
dbus_message_unref(m);
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return ret;
}
static int attach(DBusConnection *bus, char **args, unsigned n) {
- DBusMessage *m = NULL, *reply = NULL;
+ DBusMessage *m = NULL;
int ret = 0;
DBusError error;
unsigned i;
@@ -1486,6 +1480,8 @@ static int attach(DBusConnection *bus, char **args, unsigned n) {
dbus_error_init(&error);
for (i = 2; i < n; i++) {
+ DBusMessage *reply;
+
m = dbus_message_new_method_call(
"org.freedesktop.login1",
"/org/freedesktop/login1",
@@ -1523,9 +1519,6 @@ finish:
if (m)
dbus_message_unref(m);
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return ret;
@@ -1581,7 +1574,7 @@ finish:
}
static int terminate_seat(DBusConnection *bus, char **args, unsigned n) {
- DBusMessage *m = NULL, *reply = NULL;
+ DBusMessage *m = NULL;
int ret = 0;
DBusError error;
unsigned i;
@@ -1592,6 +1585,8 @@ static int terminate_seat(DBusConnection *bus, char **args, unsigned n) {
dbus_error_init(&error);
for (i = 1; i < n; i++) {
+ DBusMessage *reply;
+
m = dbus_message_new_method_call(
"org.freedesktop.login1",
"/org/freedesktop/login1",
@@ -1627,9 +1622,6 @@ finish:
if (m)
dbus_message_unref(m);
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return ret;
diff --git a/src/nspawn.c b/src/nspawn.c
index 8c3cf6b..6f484e7 100644
--- a/src/nspawn.c
+++ b/src/nspawn.c
@@ -197,8 +197,10 @@ static int mount_all(const char *dest) {
/* Fix the timezone, if possible */
if (asprintf(&where, "%s/%s", dest, "/etc/localtime") >= 0) {
- mount("/etc/localtime", where, "bind", MS_BIND, NULL);
- mount("/etc/localtime", where, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL);
+
+ if (mount("/etc/localtime", where, "bind", MS_BIND, NULL) >= 0)
+ mount("/etc/localtime", where, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL);
+
free(where);
}
diff --git a/src/strv.c b/src/strv.c
index 640ae3f..bb309d9 100644
--- a/src/strv.c
+++ b/src/strv.c
@@ -67,7 +67,8 @@ void strv_free(char **l) {
char **strv_copy(char **l) {
char **r, **k;
- if (!(k = r = new(char*, strv_length(l)+1)))
+ k = r = new(char*, strv_length(l)+1);
+ if (!k)
return NULL;
if (l)
@@ -198,7 +199,8 @@ char **strv_merge_concat(char **a, char **b, const char *suffix) {
if (!b)
return strv_copy(a);
- if (!(r = new(char*, strv_length(a)+strv_length(b)+1)))
+ r = new(char*, strv_length(a) + strv_length(b) + 1);
+ if (!r)
return NULL;
k = r;
@@ -324,7 +326,8 @@ char **strv_append(char **l, const char *s) {
if (!s)
return strv_copy(l);
- if (!(r = new(char*, strv_length(l)+2)))
+ r = new(char*, strv_length(l)+2);
+ if (!r)
return NULL;
for (k = r; *l; k++, l++)
diff --git a/src/systemctl.c b/src/systemctl.c
index e85a2fd..fdff2d1 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -137,6 +137,8 @@ static bool on_tty(void) {
}
static void pager_open_if_enabled(void) {
+
+ /* Cache result before we open the pager */
on_tty();
if (arg_no_pager)
@@ -1055,7 +1057,7 @@ finish:
}
static int load_unit(DBusConnection *bus, char **args) {
- DBusMessage *m = NULL, *reply = NULL;
+ DBusMessage *m = NULL;
DBusError error;
int r;
char **name;
@@ -1066,6 +1068,7 @@ static int load_unit(DBusConnection *bus, char **args) {
assert(args);
STRV_FOREACH(name, args+1) {
+ DBusMessage *reply;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
@@ -1103,9 +1106,6 @@ finish:
if (m)
dbus_message_unref(m);
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return r;
@@ -1795,7 +1795,7 @@ finish:
}
static int kill_unit(DBusConnection *bus, char **args) {
- DBusMessage *m = NULL, *reply = NULL;
+ DBusMessage *m = NULL;
int r = 0;
DBusError error;
char **name;
@@ -1812,6 +1812,7 @@ static int kill_unit(DBusConnection *bus, char **args) {
arg_kill_mode = streq(arg_kill_who, "all") ? "control-group" : "process";
STRV_FOREACH(name, args+1) {
+ DBusMessage *reply;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
@@ -1851,9 +1852,6 @@ finish:
if (m)
dbus_message_unref(m);
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return r;
@@ -3231,7 +3229,7 @@ finish:
}
static int reset_failed(DBusConnection *bus, char **args) {
- DBusMessage *m = NULL, *reply = NULL;
+ DBusMessage *m = NULL;
int r;
DBusError error;
char **name;
@@ -3243,6 +3241,7 @@ static int reset_failed(DBusConnection *bus, char **args) {
return daemon_reload(bus, args);
STRV_FOREACH(name, args+1) {
+ DBusMessage *reply;
if (!(m = dbus_message_new_method_call(
"org.freedesktop.systemd1",
@@ -3279,9 +3278,6 @@ finish:
if (m)
dbus_message_unref(m);
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return r;
diff --git a/src/util.c b/src/util.c
index 6a9fffb..2eb6ba7 100644
--- a/src/util.c
+++ b/src/util.c
@@ -782,13 +782,7 @@ int read_full_file(const char *fn, char **contents, size_t *size) {
}
}
- if (buf)
- buf[l] = 0;
- else if (!(buf = calloc(1, 1))) {
- r = -errno;
- goto finish;
- }
-
+ buf[l] = 0;
*contents = buf;
buf = NULL;
commit 8ea913b2eaadbd92e069ea6b71cc5f5df409decf
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Sep 23 01:43:28 2011 +0200
coverity: fix a couple of bugs found by coverity
diff --git a/src/binfmt.c b/src/binfmt.c
index 552d8cc..e8d6524 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 3bb430e..a71dcd0 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 7443973..53dd26f 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 c7d2da3..12079c6 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 f652110..fbb5a41 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 b8f7d67..b33a096 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 17b5e0b..8dd98f7 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 1d4aa21..f15c921 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 2489d78..b670d18 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 2b45ecb..2ae8785 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 572e622..a1b451e 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 92851b2..640ae3f 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 7caeb6d..e85a2fd 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 66e50a6..f6fe2d8 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 6033aa0..6a9fffb 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;
More information about the systemd-commits
mailing list