Commit da19d5c1 authored by Lennart Poettering's avatar Lennart Poettering

src: our lord is coverity

parent ba1a5515
...@@ -27,6 +27,8 @@ F15: ...@@ -27,6 +27,8 @@ F15:
* ply should do mkdir before writing pid file * ply should do mkdir before writing pid file
* ConditionDirectoryNotEmpty= needs to be documented
Features: Features:
* teach dbus to activate all services it finds in /etc/systemd/services/org-*.service * teach dbus to activate all services it finds in /etc/systemd/services/org-*.service
......
...@@ -30,7 +30,9 @@ ...@@ -30,7 +30,9 @@
Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate) { Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate) {
Condition *c; Condition *c;
c = new0(Condition, 1); if (!(c = new0(Condition, 1)))
return NULL;
c->type = type; c->type = type;
c->trigger = trigger; c->trigger = trigger;
c->negate = negate; c->negate = negate;
......
...@@ -1020,8 +1020,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, ...@@ -1020,8 +1020,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if (!e) if (!e)
goto oom; goto oom;
if (!(reply = dbus_message_new_method_return(message))) if (!(reply = dbus_message_new_method_return(message))) {
strv_free(e);
goto oom; goto oom;
}
strv_free(m->environment); strv_free(m->environment);
m->environment = e; m->environment = e;
...@@ -1108,8 +1110,6 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, ...@@ -1108,8 +1110,6 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
goto oom; goto oom;
} }
free(path);
if (reply) { if (reply) {
if (!dbus_connection_send(connection, reply, NULL)) if (!dbus_connection_send(connection, reply, NULL))
goto oom; goto oom;
...@@ -1117,6 +1117,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, ...@@ -1117,6 +1117,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
dbus_message_unref(reply); dbus_message_unref(reply);
} }
free(path);
return DBUS_HANDLER_RESULT_HANDLED; return DBUS_HANDLER_RESULT_HANDLED;
oom: oom:
......
...@@ -455,8 +455,6 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn ...@@ -455,8 +455,6 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn
goto oom; goto oom;
} }
free(path);
if (reply) { if (reply) {
if (!dbus_connection_send(connection, reply, NULL)) if (!dbus_connection_send(connection, reply, NULL))
goto oom; goto oom;
...@@ -464,6 +462,8 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn ...@@ -464,6 +462,8 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn
dbus_message_unref(reply); dbus_message_unref(reply);
} }
free(path);
return DBUS_HANDLER_RESULT_HANDLED; return DBUS_HANDLER_RESULT_HANDLED;
oom: oom:
......
...@@ -176,8 +176,8 @@ static dbus_bool_t bus_add_watch(DBusWatch *bus_watch, void *data) { ...@@ -176,8 +176,8 @@ static dbus_bool_t bus_add_watch(DBusWatch *bus_watch, void *data) {
} }
if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, w->fd, &ev) < 0) { if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, w->fd, &ev) < 0) {
free(w);
close_nointr_nofail(w->fd); close_nointr_nofail(w->fd);
free(w);
return FALSE; return FALSE;
} }
...@@ -236,7 +236,7 @@ static int bus_timeout_arm(Manager *m, Watch *w) { ...@@ -236,7 +236,7 @@ static int bus_timeout_arm(Manager *m, Watch *w) {
if (dbus_timeout_get_enabled(w->data.bus_timeout)) { if (dbus_timeout_get_enabled(w->data.bus_timeout)) {
timespec_store(&its.it_value, dbus_timeout_get_interval(w->data.bus_timeout) * USEC_PER_MSEC); timespec_store(&its.it_value, dbus_timeout_get_interval(w->data.bus_timeout) * USEC_PER_MSEC);
its.it_interval = its.it_interval; its.it_interval = its.it_value;
} }
if (timerfd_settime(w->fd, 0, &its, NULL) < 0) if (timerfd_settime(w->fd, 0, &its, NULL) < 0)
...@@ -269,7 +269,7 @@ static dbus_bool_t bus_add_timeout(DBusTimeout *timeout, void *data) { ...@@ -269,7 +269,7 @@ static dbus_bool_t bus_add_timeout(DBusTimeout *timeout, void *data) {
if (!(w = new0(Watch, 1))) if (!(w = new0(Watch, 1)))
return FALSE; return FALSE;
if (!(w->fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC)) < 0) if ((w->fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC)) < 0)
goto fail; goto fail;
w->type = WATCH_DBUS_TIMEOUT; w->type = WATCH_DBUS_TIMEOUT;
......
...@@ -646,7 +646,7 @@ static int enforce_groups(const ExecContext *context, const char *username, gid_ ...@@ -646,7 +646,7 @@ static int enforce_groups(const ExecContext *context, const char *username, gid_
char **i; char **i;
/* Final step, initialize any manually set supplementary groups */ /* Final step, initialize any manually set supplementary groups */
ngroups_max = (int) sysconf(_SC_NGROUPS_MAX); assert_se((ngroups_max = (int) sysconf(_SC_NGROUPS_MAX)) > 0);
if (!(gids = new(gid_t, ngroups_max))) if (!(gids = new(gid_t, ngroups_max)))
return -ENOMEM; return -ENOMEM;
......
...@@ -2615,7 +2615,7 @@ int manager_open_serialization(Manager *m, FILE **_f) { ...@@ -2615,7 +2615,7 @@ int manager_open_serialization(Manager *m, FILE **_f) {
log_debug("Serializing state to %s", path); log_debug("Serializing state to %s", path);
free(path); free(path);
if (!(f = fdopen(fd, "w+")) < 0) if (!(f = fdopen(fd, "w+")))
return -errno; return -errno;
*_f = f; *_f = f;
......
...@@ -99,17 +99,21 @@ int main(int argc, char *argv[]) { ...@@ -99,17 +99,21 @@ int main(int argc, char *argv[]) {
} }
f = fopen(fn, "re"); f = fopen(fn, "re");
free(fn);
if (!f) { if (!f) {
if (errno == ENOENT) if (errno == ENOENT) {
free(fn);
continue; continue;
}
log_error("Failed to open %s: %m", fn); log_error("Failed to open %s: %m", fn);
free(fn);
r = EXIT_FAILURE; r = EXIT_FAILURE;
continue; continue;
} }
free(fn);
for (;;) { for (;;) {
char line[LINE_MAX], *l, *t; char line[LINE_MAX], *l, *t;
......
...@@ -785,6 +785,7 @@ static void mount_enter_signal(Mount *m, MountState state, bool success) { ...@@ -785,6 +785,7 @@ static void mount_enter_signal(Mount *m, MountState state, bool success) {
wait_for_exit = true; wait_for_exit = true;
set_free(pid_set); set_free(pid_set);
pid_set = NULL;
} }
} }
......
...@@ -122,7 +122,8 @@ static int replay(const char *root) { ...@@ -122,7 +122,8 @@ static int replay(const char *root) {
FILE *pack = NULL; FILE *pack = NULL;
char line[LINE_MAX]; char line[LINE_MAX];
int r = 0; int r = 0;
char *pack_fn = NULL, c; char *pack_fn = NULL;
int c;
bool on_ssd, ready = false; bool on_ssd, ready = false;
int prio; int prio;
int inotify_fd = -1; int inotify_fd = -1;
......
...@@ -406,7 +406,7 @@ static int sysv_fix_order(Service *s) { ...@@ -406,7 +406,7 @@ static int sysv_fix_order(Service *s) {
/* FIXME: Maybe we should compare the name here lexicographically? */ /* FIXME: Maybe we should compare the name here lexicographically? */
if (!(r = unit_add_dependency(UNIT(s), d, UNIT(t), true)) < 0) if ((r = unit_add_dependency(UNIT(s), d, UNIT(t), true)) < 0)
return r; return r;
} }
...@@ -1024,7 +1024,7 @@ static int fsck_fix_order(Service *s) { ...@@ -1024,7 +1024,7 @@ static int fsck_fix_order(Service *s) {
else else
continue; continue;
if (!(r = unit_add_dependency(UNIT(s), d, UNIT(t), true)) < 0) if ((r = unit_add_dependency(UNIT(s), d, UNIT(t), true)) < 0)
return r; return r;
} }
...@@ -1882,6 +1882,7 @@ static void service_enter_signal(Service *s, ServiceState state, bool success) { ...@@ -1882,6 +1882,7 @@ static void service_enter_signal(Service *s, ServiceState state, bool success) {
wait_for_exit = true; wait_for_exit = true;
set_free(pid_set); set_free(pid_set);
pid_set = NULL;
} }
} }
......
...@@ -227,7 +227,7 @@ int main(int argc, char *argv[]) { ...@@ -227,7 +227,7 @@ int main(int argc, char *argv[]) {
if ((pollfd[i].fd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK|TFD_CLOEXEC)) < 0) { if ((pollfd[i].fd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK|TFD_CLOEXEC)) < 0) {
log_error("timerfd_create(): %m"); log_error("timerfd_create(): %m");
failed = false; failed = true;
} }
} }
......
...@@ -1066,6 +1066,7 @@ static void socket_enter_signal(Socket *s, SocketState state, bool success) { ...@@ -1066,6 +1066,7 @@ static void socket_enter_signal(Socket *s, SocketState state, bool success) {
wait_for_exit = true; wait_for_exit = true;
set_free(pid_set); set_free(pid_set);
pid_set = NULL;
} }
} }
...@@ -1695,6 +1696,7 @@ static void socket_timer_event(Unit *u, uint64_t elapsed, Watch *w) { ...@@ -1695,6 +1696,7 @@ static void socket_timer_event(Unit *u, uint64_t elapsed, Watch *w) {
case SOCKET_START_PRE: case SOCKET_START_PRE:
log_warning("%s starting timed out. Terminating.", u->meta.id); log_warning("%s starting timed out. Terminating.", u->meta.id);
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false); socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
break;
case SOCKET_START_POST: case SOCKET_START_POST:
log_warning("%s starting timed out. Stopping.", u->meta.id); log_warning("%s starting timed out. Stopping.", u->meta.id);
......
...@@ -78,9 +78,11 @@ char **strv_copy(char **l) { ...@@ -78,9 +78,11 @@ char **strv_copy(char **l) {
return r; return r;
fail: fail:
for (k--, l--; k >= r; k--, l--) for (k--; k >= r; k--)
free(*k); free(*k);
free(r);
return NULL; return NULL;
} }
...@@ -435,6 +437,8 @@ char **strv_env_merge(unsigned n_lists, ...) { ...@@ -435,6 +437,8 @@ char **strv_env_merge(unsigned n_lists, ...) {
return r; return r;
fail: fail:
va_end(ap);
for (k--; k >= r; k--) for (k--; k >= r; k--)
free(*k); free(*k);
......
...@@ -687,6 +687,7 @@ static void swap_enter_signal(Swap *s, SwapState state, bool success) { ...@@ -687,6 +687,7 @@ static void swap_enter_signal(Swap *s, SwapState state, bool success) {
wait_for_exit = true; wait_for_exit = true;
set_free(pid_set); set_free(pid_set);
pid_set = NULL;
} }
} }
......
...@@ -2035,8 +2035,7 @@ char **unit_full_printf_strv(Unit *u, char **l) { ...@@ -2035,8 +2035,7 @@ char **unit_full_printf_strv(Unit *u, char **l) {
return r; return r;
fail: fail:
j--; for (j--; j >= r; j--)
while (j >= r)
free(*j); free(*j);
free(r); free(r);
......
...@@ -3582,7 +3582,6 @@ char *normalize_env_assignment(const char *s) { ...@@ -3582,7 +3582,6 @@ char *normalize_env_assignment(const char *s) {
free(p); free(p);
if (!value) { if (!value) {
free(p);
free(name); free(name);
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment