3ce7d3
diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c
3ce7d3
index f657c30..ff9a2d2 100644
3ce7d3
--- a/bin/dig/dighost.c
3ce7d3
+++ b/bin/dig/dighost.c
3ce7d3
@@ -1694,6 +1694,13 @@ clear_query(dig_query_t *query) {
bc5dde
 
3ce7d3
 	if (query->timer != NULL)
3ce7d3
 		isc_timer_detach(&query->timer);
3ce7d3
+
bc5dde
+	if (query->waiting_senddone) {
bc5dde
+		debug("send_done not yet called");
bc5dde
+		query->pending_free = ISC_TRUE;
bc5dde
+		return;
bc5dde
+	}
bc5dde
+
bc5dde
 	lookup = query->lookup;
bc5dde
 
bc5dde
 	if (lookup->current_query == query)
3ce7d3
@@ -1719,10 +1726,7 @@ clear_query(dig_query_t *query) {
bc5dde
 	isc_mempool_put(commctx, query->recvspace);
bc5dde
 	isc_buffer_invalidate(&query->recvbuf);
bc5dde
 	isc_buffer_invalidate(&query->lengthbuf);
bc5dde
-	if (query->waiting_senddone)
bc5dde
-		query->pending_free = ISC_TRUE;
bc5dde
-	else
bc5dde
-		isc_mem_free(mctx, query);
bc5dde
+	isc_mem_free(mctx, query);
bc5dde
 }
bc5dde
 
bc5dde
 /*%
3ce7d3
@@ -2811,9 +2815,9 @@ send_done(isc_task_t *_task, isc_event_t *event) {
bc5dde
 	isc_event_free(&event);
bc5dde
 
bc5dde
 	if (query->pending_free)
bc5dde
-		isc_mem_free(mctx, query);
bc5dde
+		clear_query(query);
bc5dde
 
bc5dde
-	check_if_done();
bc5dde
+	check_next_lookup(l);
bc5dde
 	UNLOCK_LOOKUP;
bc5dde
 }
bc5dde