diff --git a/src/queue.c b/src/queue.c
index 729ded84218182a2674b67476033787284d5f8ee..af84c4b1f5e7e80fac05e5b122703fa718b7fead 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -212,6 +212,9 @@ struct task *queue_gettask(struct queue *q, const struct task *prev, int blockin
 
     /* Another one bites the dust. */
     const int qcount = q->count -= 1;
+    
+    /* Get a pointer on the task that we want to return. */
+    res = &qtasks[tid];
 
     /* Swap this task with the last task and re-heap. */
     int k = ind;