summaryrefslogtreecommitdiff
path: root/src/shared/dbus-loop.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-24 19:45:16 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-31 14:36:12 -0400
commite62d8c3944745ed276e6d4f33153009860e5cfc5 (patch)
treee7f70ed3b80581017b6340723ab6f1d6b9c30bad /src/shared/dbus-loop.c
parent3c8bed4ee061f96acb4d70a591a9849bddd2a659 (diff)
Modernization
Use _cleanup_ and wrap lines to ~80 chars and such.
Diffstat (limited to 'src/shared/dbus-loop.c')
-rw-r--r--src/shared/dbus-loop.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/shared/dbus-loop.c b/src/shared/dbus-loop.c
index da0a00443a..fec8998bc1 100644
--- a/src/shared/dbus-loop.c
+++ b/src/shared/dbus-loop.c
@@ -44,7 +44,7 @@ typedef struct EpollData {
} EpollData;
static dbus_bool_t add_watch(DBusWatch *watch, void *data) {
- EpollData *e;
+ EpollData _cleanup_free_ *e = NULL;
struct epoll_event ev;
assert(watch);
@@ -63,10 +63,8 @@ static dbus_bool_t add_watch(DBusWatch *watch, void *data) {
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 +72,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 +84,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;
+ EpollData _cleanup_free_ *e = NULL;
assert(watch);
@@ -106,8 +102,6 @@ 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) {
@@ -186,7 +180,7 @@ fail:
}
static void remove_timeout(DBusTimeout *timeout, void *data) {
- EpollData *e;
+ EpollData _cleanup_free_ *e = NULL;
assert(timeout);
@@ -196,7 +190,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) {