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