coverity: fix a couple of bugs found by coverity

This commit is contained in:
Lennart Poettering 2011-09-23 01:43:28 +02:00
parent 0fe9972f3c
commit 8ea913b2ea
15 changed files with 36 additions and 13 deletions

View file

@ -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]);

View file

@ -314,7 +314,7 @@ int config_parse(
continuation = c;
else {
continuation = strdup(l);
if (!c) {
if (!continuation) {
r = -ENOMEM;
goto finish;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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;
}

View file

@ -246,7 +246,7 @@ static int write_data_local_rtc(void) {
p++;
e = strchr(p, '\n');
if (!p) {
if (!e) {
free(s);
return -EIO;
}

View file

@ -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;