summaryrefslogtreecommitdiff
path: root/src/shared/dbus-loop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/dbus-loop.c')
-rw-r--r--src/shared/dbus-loop.c38
1 files changed, 12 insertions, 26 deletions
diff --git a/src/shared/dbus-loop.c b/src/shared/dbus-loop.c
index da0a00443a..c533242220 100644
--- a/src/shared/dbus-loop.c
+++ b/src/shared/dbus-loop.c
@@ -44,8 +44,8 @@ typedef struct EpollData {
} EpollData;
static dbus_bool_t add_watch(DBusWatch *watch, void *data) {
- EpollData *e;
- struct epoll_event ev;
+ _cleanup_free_ EpollData *e = NULL;
+ struct epoll_event ev = {};
assert(watch);
@@ -57,16 +57,13 @@ static dbus_bool_t add_watch(DBusWatch *watch, void *data) {
e->object = watch;
e->is_timeout = false;
- zero(ev);
ev.events = bus_flags_to_events(watch);
ev.data.ptr = e;
if (epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_ADD, e->fd, &ev) < 0) {
- if (errno != EEXIST) {
- free(e);
+ if (errno != EEXIST)
return FALSE;
- }
/* Hmm, bloody D-Bus creates multiple watches on the
* same fd. epoll() does not like that. As a dirty
@@ -74,14 +71,11 @@ static dbus_bool_t add_watch(DBusWatch *watch, void *data) {
* one we can safely add to the epoll(). */
e->fd = dup(e->fd);
- if (e->fd < 0) {
- free(e);
+ if (e->fd < 0)
return FALSE;
- }
if (epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_ADD, e->fd, &ev) < 0) {
close_nointr_nofail(e->fd);
- free(e);
return FALSE;
}
@@ -89,12 +83,13 @@ static dbus_bool_t add_watch(DBusWatch *watch, void *data) {
}
dbus_watch_set_data(watch, e, NULL);
+ e = NULL; /* prevent freeing */
return TRUE;
}
static void remove_watch(DBusWatch *watch, void *data) {
- EpollData *e;
+ _cleanup_free_ EpollData *e = NULL;
assert(watch);
@@ -106,13 +101,11 @@ static void remove_watch(DBusWatch *watch, void *data) {
if (e->fd_is_dupped)
close_nointr_nofail(e->fd);
-
- free(e);
}
static void toggle_watch(DBusWatch *watch, void *data) {
EpollData *e;
- struct epoll_event ev;
+ struct epoll_event ev = {};
assert(watch);
@@ -120,21 +113,18 @@ static void toggle_watch(DBusWatch *watch, void *data) {
if (!e)
return;
- zero(ev);
- ev.events = bus_flags_to_events(watch);
ev.data.ptr = e;
+ ev.events = bus_flags_to_events(watch);
assert_se(epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_MOD, e->fd, &ev) == 0);
}
static int timeout_arm(EpollData *e) {
- struct itimerspec its;
+ struct itimerspec its = {};
assert(e);
assert(e->is_timeout);
- zero(its);
-
if (dbus_timeout_get_enabled(e->object)) {
timespec_store(&its.it_value, dbus_timeout_get_interval(e->object) * USEC_PER_MSEC);
its.it_interval = its.it_value;
@@ -148,7 +138,7 @@ static int timeout_arm(EpollData *e) {
static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) {
EpollData *e;
- struct epoll_event ev;
+ struct epoll_event ev = {};
assert(timeout);
@@ -166,7 +156,6 @@ static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) {
if (timeout_arm(e) < 0)
goto fail;
- zero(ev);
ev.events = EPOLLIN;
ev.data.ptr = e;
@@ -186,7 +175,7 @@ fail:
}
static void remove_timeout(DBusTimeout *timeout, void *data) {
- EpollData *e;
+ _cleanup_free_ EpollData *e = NULL;
assert(timeout);
@@ -196,7 +185,6 @@ static void remove_timeout(DBusTimeout *timeout, void *data) {
assert_se(epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_DEL, e->fd, NULL) >= 0);
close_nointr_nofail(e->fd);
- free(e);
}
static void toggle_timeout(DBusTimeout *timeout, void *data) {
@@ -234,13 +222,11 @@ int bus_loop_open(DBusConnection *c) {
int bus_loop_dispatch(int fd) {
int n;
- struct epoll_event event;
+ struct epoll_event event = {};
EpollData *d;
assert(fd >= 0);
- zero(event);
-
n = epoll_wait(fd, &event, 1, 0);
if (n < 0)
return errno == EAGAIN || errno == EINTR ? 0 : -errno;