From 1be4b9bd156d6e0ac4849b6d71ad4c66f9d7f8ce Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 22 Jan 2015 20:11:07 +0000 Subject: [PATCH] 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. https://bugs.freedesktop.org/show_bug.cgi?id=88808 --- dbus/dbus-socket-set-epoll.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dbus/dbus-socket-set-epoll.c b/dbus/dbus-socket-set-epoll.c index 5bd8d5a..4692cbe 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); -- 2.9.3