Skip to content

DiG: fix lookup reference counting bug

Arаm Sаrgsyаn requested to merge 3478-dig-lookup-reference-counting-bug into main

When DiG finishes its work with a lookup (due to success or error), it calls the clear_current_lookup() function, which decreases the lookup's reference count. That decrease action is the counterpart of the initial creation of the reference counter, so this function was designed in such a way that it should decrease the reference count only once, when there are no more active queries in the lookup.

The way it checks whether there are any active queries is by looking at the queries list of the lookup object - if it's NULL then there are no active queries. But that is not always true - the cancel_lookup() function, when canceling the queries one by one, also removes them from the lookup's list, but in NSSEARCH mode, when the queries are working in parallel, some of those queries can be still active. And when their recv_done() callback gets called, it sees that the lookup has been canceled, calls clear_current_lookup(), which decreases the reference count every time for each query that was still active (because ISC_LIST_HEAD(lookup->q) is NULL) and results in a reference counting error.

Fix the issue by introducing a new "cleared" property for the lookup, which will ensure that the clear_current_lookup() function does its job only once per lookup.

Closes #3478 (closed)

Merge request reports