e55890
diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c
27025e
index c06c804..e75b8b7 100644
e55890
--- a/bin/dig/dighost.c
e55890
+++ b/bin/dig/dighost.c
27025e
@@ -1816,6 +1816,13 @@ clear_query(dig_query_t *query) {
e55890
 
e55890
 	if (query->timer != NULL)
e55890
 		isc_timer_detach(&query->timer);
e55890
+
e55890
+	if (query->waiting_senddone) {
e55890
+		debug("send_done not yet called");
27025e
+		query->pending_free = true;
e55890
+		return;
e55890
+	}
e55890
+
e55890
 	lookup = query->lookup;
e55890
 
e55890
 	if (lookup->current_query == query)
27025e
@@ -1841,10 +1848,7 @@ clear_query(dig_query_t *query) {
e55890
 	isc_mempool_put(commctx, query->recvspace);
e55890
 	isc_buffer_invalidate(&query->recvbuf);
e55890
 	isc_buffer_invalidate(&query->lengthbuf);
e55890
-	if (query->waiting_senddone)
27025e
-		query->pending_free = true;
e55890
-	else
e55890
-		isc_mem_free(mctx, query);
e55890
+	isc_mem_free(mctx, query);
e55890
 }
e55890
 
e55890
 /*%
27025e
@@ -2895,9 +2899,9 @@ send_done(isc_task_t *_task, isc_event_t *event) {
e55890
 	isc_event_free(&event);
e55890
 
e55890
 	if (query->pending_free)
e55890
-		isc_mem_free(mctx, query);
e55890
+		clear_query(query);
e55890
 
e55890
-	check_if_done();
e55890
+	check_next_lookup(l);
e55890
 	UNLOCK_LOOKUP;
e55890
 }
e55890