lib/resolver: NULL out callback before call

The callback itself might want to reschedule the resolver, so it is
useful to clear out the callback field before making the call instead of
after.

Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
David Lamparter 2019-05-23 14:25:58 +02:00
parent fe9e7b71cf
commit 50cdb6cf95

View File

@ -145,14 +145,17 @@ static void ares_address_cb(void *arg, int status, int timeouts,
{ {
struct resolver_query *query = (struct resolver_query *)arg; struct resolver_query *query = (struct resolver_query *)arg;
union sockunion addr[16]; union sockunion addr[16];
void (*callback)(struct resolver_query *, int, union sockunion *);
size_t i; size_t i;
callback = query->callback;
query->callback = NULL;
if (status != ARES_SUCCESS) { if (status != ARES_SUCCESS) {
if (resolver_debug) if (resolver_debug)
zlog_debug("[%p] Resolving failed", query); zlog_debug("[%p] Resolving failed", query);
query->callback(query, -1, NULL); callback(query, -1, NULL);
query->callback = NULL;
return; return;
} }
@ -174,8 +177,7 @@ static void ares_address_cb(void *arg, int status, int timeouts,
if (resolver_debug) if (resolver_debug)
zlog_debug("[%p] Resolved with %d results", query, (int)i); zlog_debug("[%p] Resolved with %d results", query, (int)i);
query->callback(query, i, &addr[0]); callback(query, i, &addr[0]);
query->callback = NULL;
} }
void resolver_resolve(struct resolver_query *query, int af, void resolver_resolve(struct resolver_query *query, int af,