--- async_sock.c.orig 2013-07-17 19:22:43.493922674 -0700 +++ async_sock.c 2013-07-17 19:29:06.393912269 -0700 @@ -306,7 +306,10 @@ post_errno: tevent_req_error(result, state->sys_errno); done: - fcntl(fd, F_SETFL, state->old_sockflags); + if (fcntl(fd, F_SETFL, state->old_sockflags) == -1) { + state->sys_errno = errno; + tevent_req_error(result, state->sys_errno); + } return tevent_req_post(result, ev); } @@ -352,7 +355,9 @@ tevent_req_data(req, struct async_connect_state); int err; - fcntl(state->fd, F_SETFL, state->old_sockflags); + if (fcntl(state->fd, F_SETFL, state->old_sockflags) == -1) { + return -1; + } if (tevent_req_is_unix_error(req, &err)) { *perrno = err;