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