summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2016-09-16 23:37:20 -0700
committerJeremy Allison <jra@samba.org>2016-09-19 07:11:59 +0200
commit085542fc93b3c603e8cda6e481e94d5fe2dfc669 (patch)
treec40da7a62143acffce4821049fc3b649d4c4bd18 /lib
parentee64d3f1d89a3ceb61d035e776c8235a19c8a2cf (diff)
downloadsamba-085542fc93b3c603e8cda6e481e94d5fe2dfc669.tar.gz
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 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Mon Sep 19 07:12:00 CEST 2016 on sn-devel-144
Diffstat (limited to 'lib')
-rw-r--r--lib/poll_funcs/poll_funcs_tevent.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/poll_funcs/poll_funcs_tevent.c b/lib/poll_funcs/poll_funcs_tevent.c
index 233e9110a47..4dd09a23bda 100644
--- a/lib/poll_funcs/poll_funcs_tevent.c
+++ b/lib/poll_funcs/poll_funcs_tevent.c
@@ -504,10 +504,21 @@ static bool poll_funcs_context_slot_find(struct poll_funcs_state *state,
size_t num_contexts = talloc_array_length(state->contexts);
size_t i;
+ /* Look for an existing match first. */
for (i=0; i<num_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; i<num_contexts; i++) {
+ struct poll_funcs_tevent_context *ctx = state->contexts[i];
+
+ if (ctx == NULL) {
*slot = i;
return true;
}