From 3cdbee6cbc580629b64e0d92e745835ebb9bd95d Mon Sep 17 00:00:00 2001 From: haorenfsa Date: Wed, 26 Apr 2017 22:30:10 +0800 Subject: [PATCH] read_fd should always have a certain value when create error occurs [fix: while using eventfd, when error occurs during creating eventfd, a random fd will be closed] --- src/core/lib/iomgr/wakeup_fd_eventfd.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/lib/iomgr/wakeup_fd_eventfd.cc b/src/core/lib/iomgr/wakeup_fd_eventfd.cc index dcf7dab71fb..d68c9ada1f2 100644 --- a/src/core/lib/iomgr/wakeup_fd_eventfd.cc +++ b/src/core/lib/iomgr/wakeup_fd_eventfd.cc @@ -32,12 +32,11 @@ #include "src/core/lib/profiling/timers.h" static grpc_error* eventfd_create(grpc_wakeup_fd* fd_info) { - int efd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); - if (efd < 0) { + fd_info->read_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); + fd_info->write_fd = -1; + if (fd_info->read_fd < 0) { return GRPC_OS_ERROR(errno, "eventfd"); } - fd_info->read_fd = efd; - fd_info->write_fd = -1; return GRPC_ERROR_NONE; }