From 5601576d9d182ca1741da6db5eb7cae405333329 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 2 May 2014 09:20:40 +0000 Subject: [PATCH] messaging3: Add comments about not touching "waiters" Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- source3/lib/messages.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 065782ac1b..6a08531f2a 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -491,6 +491,14 @@ struct tevent_req *messaging_filtered_read_send( state->filter = filter; state->private_data = private_data; + /* + * We add ourselves to the "new_waiters" array, not the "waiters" + * array. If we are called from within messaging_read_done, + * messaging_dispatch_rec will be in an active for-loop on + * "waiters". We must be careful not to mess with this array, because + * it could mean that a single event is being delivered twice. + */ + new_waiters_len = talloc_array_length(msg_ctx->new_waiters); if (new_waiters_len == msg_ctx->num_new_waiters) { @@ -521,6 +529,14 @@ static void messaging_filtered_read_cleanup(struct tevent_req *req, tevent_req_set_cleanup_fn(req, NULL); + /* + * Just set the [new_]waiters entry to NULL, be careful not to mess + * with the other "waiters" array contents. We are often called from + * within "messaging_dispatch_rec", which loops over + * "waiters". Messing with the "waiters" array will mess up that + * for-loop. + */ + for (i=0; inum_waiters; i++) { if (msg_ctx->waiters[i] == req) { msg_ctx->waiters[i] = NULL; -- 2.34.1