Subject: Re-entrancy problems

Re-entrancy problems

From: William Ahern <william_at_25thandclement.com>
Date: 2006-06-08

I'm not sure if "re-entrancy" is the right term, but there is a critical
issue in Ares. Maybe it's been discussed before.

If a user calls ares_destroy() from a callback, then the library will access
invalid memory as it unwinds. One instance is in end_query in
ares_process.c.

My typical solution is to push a pointer to a flag in automatic storage of
the call frame onto a stack of the main context object before every
callback. The object is popped when the callback returns (of course checking
the flag first).

In this case, ares_destroy() would traverse this stack and mark all the
flags to communicate to lower call frames that the context pointer is dead.
Fortunately, most places in the library return immediately after any
function which could issue a callback, so this device would only need to be
put in a few places.

I'll try to work out a patch for trunk, unless there are objections. A
workaround is to externally keep track of how many times the ares library
has been entered, and to delay object destruction until no ares routes are
live. But IMO that's rather ugly.
Received on Thu Jun 8 23:29:41 2006