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