[PATCH] tevent: Protect against fde's lost during a callback

Volker Lendecke vl at samba.org
Thu Feb 17 08:12:52 MST 2011


---
 lib/tevent/tevent_select.c   |    6 +++++-
 lib/tevent/tevent_standard.c |    6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/tevent/tevent_select.c b/lib/tevent/tevent_select.c
index 8cc6d06..b2fc95b 100644
--- a/lib/tevent/tevent_select.c
+++ b/lib/tevent/tevent_select.c
@@ -184,12 +184,16 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru
 	}
 
 	if (selrtn > 0) {
+		struct tevent_fd *next;
+
 		/* at least one file descriptor is ready - check
 		   which ones and call the handler, being careful to allow
 		   the handler to remove itself when called */
-		for (fde = select_ev->ev->fd_events; fde; fde = fde->next) {
+		for (fde = select_ev->ev->fd_events; fde; fde = next) {
 			uint16_t flags = 0;
 
+			next = fde->next;
+
 			if (FD_ISSET(fde->fd, &r_fds)) flags |= TEVENT_FD_READ;
 			if (FD_ISSET(fde->fd, &w_fds)) flags |= TEVENT_FD_WRITE;
 			if (flags) {
diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c
index a68a03c..436f535 100644
--- a/lib/tevent/tevent_standard.c
+++ b/lib/tevent/tevent_standard.c
@@ -497,12 +497,16 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva
 	}
 
 	if (selrtn > 0) {
+		struct tevent_fd *next;
+
 		/* at least one file descriptor is ready - check
 		   which ones and call the handler, being careful to allow
 		   the handler to remove itself when called */
-		for (fde = std_ev->ev->fd_events; fde; fde = fde->next) {
+		for (fde = std_ev->ev->fd_events; fde; fde = next) {
 			uint16_t flags = 0;
 
+			next = fde->next;
+
 			if (FD_ISSET(fde->fd, &r_fds)) flags |= TEVENT_FD_READ;
 			if (FD_ISSET(fde->fd, &w_fds)) flags |= TEVENT_FD_WRITE;
 			if (flags & fde->flags) {
-- 
1.7.3.2


--lrZ03NoBR/3+SXJZ--


More information about the samba-technical mailing list