diff options
author | Philip Withnall <withnall@endlessm.com> | 2015-01-22 20:11:07 +0000 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2017-02-22 11:06:22 +0000 |
commit | e411f221579b9a8643bd456b624bd3e219b44b83 (patch) | |
tree | e7cd19d89b43fc2b97b6f580d200bf46f865ac83 | |
parent | 6b17dd68df208c5057d520493a1c23b793598fd2 (diff) |
dbus-socket-set-epoll: initialize all bytes of struct epoll_event
This should be a no-op, but it shuts Valgrind up.
The reason for the warning is that we fill in event.events and
event.data.fd, but the union event.data actually contains more bytes
than that. We'll get the same partially initialized union back from the
kernel in socket_set_epoll_poll(), where we take events[i].data.fd and
ignore the rest. So the current code is safe, but valgrind is right to
worry.
This is an expanded version of an older patch by Simon McVittie.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88808
Signed-off-by: Simon McVittie <smcv@debian.org>
-rw-r--r-- | dbus/dbus-socket-set-epoll.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/dbus/dbus-socket-set-epoll.c b/dbus/dbus-socket-set-epoll.c index 5bd8d5a0..4692cbe4 100644 --- a/dbus/dbus-socket-set-epoll.c +++ b/dbus/dbus-socket-set-epoll.c @@ -144,6 +144,7 @@ socket_set_epoll_add (DBusSocketSet *set, struct epoll_event event; int err; + _DBUS_ZERO (event); event.data.fd = fd; if (enabled) @@ -196,6 +197,7 @@ socket_set_epoll_enable (DBusSocketSet *set, struct epoll_event event; int err; + _DBUS_ZERO (event); event.data.fd = fd; event.events = watch_flags_to_epoll_events (flags); @@ -251,6 +253,7 @@ socket_set_epoll_disable (DBusSocketSet *set, * work on 2.6.32). Compile this file with -DTEST_BEHAVIOUR_OF_EPOLLET for * test code. */ + _DBUS_ZERO (event); event.data.fd = fd; event.events = EPOLLET; @@ -270,7 +273,8 @@ socket_set_epoll_remove (DBusSocketSet *set, int err; /* Kernels < 2.6.9 require a non-NULL struct pointer, even though its * contents are ignored */ - struct epoll_event dummy = { 0 }; + struct epoll_event dummy; + _DBUS_ZERO (dummy); if (epoll_ctl (self->epfd, EPOLL_CTL_DEL, fd, &dummy) == 0) return; @@ -346,6 +350,8 @@ main (void) int fd = 0; /* stdin */ int ret; + _DBUS_ZERO (input); + input.events = EPOLLHUP | EPOLLET; ret = epoll_ctl (epfd, EPOLL_CTL_ADD, fd, &input); printf ("ctl ADD: %d\n", ret); |