From e9c397b21d4ab29e5f691f20ab045cb72109c781 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Mon, 18 Jan 2010 12:35:10 -0500 Subject: Fix timeout memory heirarchy This fixes two issues: 1) Eliminates a double-free when a timeout occurs (we were freeing the running event context) 2) Ensures that we don't continue to schedule unnecessary timeout checks --- server/resolv/async_resolv.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/server/resolv/async_resolv.c b/server/resolv/async_resolv.c index 0be791851..ce92c8a7d 100644 --- a/server/resolv/async_resolv.c +++ b/server/resolv/async_resolv.c @@ -160,11 +160,23 @@ static void check_fd_timeouts(struct tevent_context *ev, struct tevent_timer *te, struct timeval current_time, void *private_data) { - struct resolv_ctx *ctx = private_data; + struct resolv_ctx *ctx = talloc_get_type(private_data, struct resolv_ctx); DEBUG(9, ("Checking for DNS timeouts\n")); + + /* NULLify the timeout_watcher so we don't + * free it in the _done() function if it + * gets called. Now that we're already in + * the handler, tevent will take care of + * freeing it when it returns. + */ + ctx->timeout_watcher = NULL; + ares_process_fd(ctx->channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); - add_timeout_timer(ev, ctx); + + if (ctx->pending_requests > 0) { + add_timeout_timer(ev, ctx); + } } static void -- cgit