diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/poll_funcs/poll_funcs_tevent.c | 14 |
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); |