From a41ef8d5133a98704915d4b760c981b7ed2c36ef Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 5 Jul 2019 10:00:39 +0530 Subject: [PATCH] Abort if addWatch during initialization of poll data fails --- glfw/backend_utils.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/glfw/backend_utils.c b/glfw/backend_utils.c index 1dafa8c5f..edee36b63 100644 --- a/glfw/backend_utils.c +++ b/glfw/backend_utils.c @@ -229,15 +229,16 @@ drain_wakeup_fd(int fd, int events UNUSED, void* data UNUSED) { bool initPollData(EventLoopData *eld, int display_fd) { - addWatch(eld, "display", display_fd, POLLIN, 1, NULL, NULL); + if (!addWatch(eld, "display", display_fd, POLLIN, 1, NULL, NULL)) return false; #ifdef HAS_EVENT_FD eld->wakeupFd = eventfd(0, 0); if (eld->wakeupFd == -1) return false; - addWatch(eld, "wakeup", eld->wakeupFd, POLLIN, 1, drain_wakeup_fd, NULL); + const int wakeup_fd = eld->wakeupFd; #else if (pipe2(eld->wakeupFds, O_CLOEXEC | O_NONBLOCK) != 0) return false; - addWatch(eld, "wakeup", eld->wakeupFds[0], POLLIN, 1, drain_wakeup_fd, NULL); + const int wakeup_fd = eld->wakeupFds[0]; #endif + if (!addWatch(eld, "wakeup", wakeup_fd, POLLIN, 1, drain_wakeup_fd, NULL)) return false; return true; }