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
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;
}