From 7f0a86bbbb296da90dcb40dee16b4a68efa7b276 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 19 Sep 2016 11:47:22 -0700 Subject: 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 --- lib/poll_funcs/poll_funcs_tevent.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/poll_funcs/poll_funcs_tevent.c b/lib/poll_funcs/poll_funcs_tevent.c index 6052077ff3f..65adb2da8c2 100644 --- a/lib/poll_funcs/poll_funcs_tevent.c +++ b/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); -- cgit v1.2.1