Fix ugly mistake in BLI_task - freeing while some tasks are still being processed.
authorBastien Montagne <montagne29@wanadoo.fr>
Fri, 3 Mar 2017 16:12:03 +0000 (17:12 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Fri, 3 Mar 2017 16:12:03 +0000 (17:12 +0100)
Freeing pool was calling `BLI_task_pool_stop()`, which only clears
pool's tasks that are in TODO queue, whithout ensuring no more tasks
from that pool are being processed in worker threads.

This could lead to use-after-free random (and seldom) crashes.

Now use instead `BLI_task_pool_cancel()`, which does waits for all tasks
being processed to finish, before returning.

source/blender/blenlib/intern/task.c

index 5286e6ffb960f326ef23016592ab8d6a0c9066e4..359360d59c41dc12b42202be6cff6e7efaf88602 100644 (file)
@@ -565,7 +565,7 @@ TaskPool *BLI_task_pool_create_background(TaskScheduler *scheduler, void *userda
 
 void BLI_task_pool_free(TaskPool *pool)
 {
-       BLI_task_pool_stop(pool);
+       BLI_task_pool_cancel(pool);
 
        BLI_mutex_end(&pool->num_mutex);
        BLI_condition_end(&pool->num_cond);