summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2016-09-19 11:47:22 -0700
committerKarolin Seeger <kseeger@samba.org>2016-09-21 11:55:16 +0200
commit7f0a86bbbb296da90dcb40dee16b4a68efa7b276 (patch)
tree19944b56e9b88018448916649c48da9b90e649a6 /lib
parent6411b3dfbad88dc5f3c068c7a02a8332bdf4d29c (diff)
downloadsamba-7f0a86bbbb296da90dcb40dee16b4a68efa7b276.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 Back-port from 085542fc93b3c603e8cda6e481e94d5fe2dfc669 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/poll_funcs/poll_funcs_tevent.c14
1 files changed, 13 insertions, 1 deletions
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; i<state->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<state->num_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);