From 0b0574e31aa2aed76b25b891dc87f50bf117660f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 19 Sep 2016 11:47:22 -0700 Subject: [PATCH] lib: poll_funcs : poll_funcs_context_slot_find can select the wrong slot to replace. Look for an exact match first, before a free slot. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12272 Back-port from 085542fc93b3c603e8cda6e481e94d5fe2dfc669 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme Autobuild-User(v4-3-test): Karolin Seeger Autobuild-Date(v4-3-test): Tue Sep 20 13:38:44 CEST 2016 on sn-devel-104 --- source3/lib/poll_funcs/poll_funcs_tevent.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source3/lib/poll_funcs/poll_funcs_tevent.c b/source3/lib/poll_funcs/poll_funcs_tevent.c index aba989d8df5..a18cb235759 100644 --- a/source3/lib/poll_funcs/poll_funcs_tevent.c +++ b/source3/lib/poll_funcs/poll_funcs_tevent.c @@ -318,15 +318,27 @@ static bool poll_funcs_context_slot_find(struct poll_funcs_state *state, struct poll_funcs_tevent_context **contexts; unsigned i; + /* Look for an existing match first. */ for (i=0; inum_contexts; i++) { struct poll_funcs_tevent_context *ctx = state->contexts[i]; - if ((ctx == NULL) || (ctx->ev == ev)) { + if (ctx != NULL && ctx->ev == ev) { *slot = i; return true; } } + /* Now look for a free slot. */ + for (i=0; inum_contexts; i++) { + struct poll_funcs_tevent_context *ctx = state->contexts[i]; + + if (ctx == NULL) { + *slot = i; + return true; + } + } + + contexts = talloc_realloc(state, state->contexts, struct poll_funcs_tevent_context *, state->num_contexts + 1); -- 2.47.2