From 4312cb854517ded8a576c2b53c8e92258eed7cce Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 6 Dec 2021 17:46:21 +0100 Subject: Fix memory leak when loading large asset libraries --- source/blender/editors/space_file/filelist.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source/blender/editors/space_file/filelist.c') diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 6593894d9a6..a580cf672f4 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -1624,6 +1624,9 @@ static void filelist_cache_preview_runf(TaskPool *__restrict pool, void *taskdat preview->icon_id = BKE_icon_imbuf_create(imbuf); } + /* Move ownership to the done queue. */ + preview_taskdata->preview = NULL; + BLI_thread_queue_push(cache->previews_done, preview); atomic_fetch_and_sub_z(&cache->previews_todo_count, 1); @@ -1633,6 +1636,12 @@ static void filelist_cache_preview_runf(TaskPool *__restrict pool, void *taskdat static void filelist_cache_preview_freef(TaskPool *__restrict UNUSED(pool), void *taskdata) { FileListEntryPreviewTaskData *preview_taskdata = taskdata; + + /* In case the preview wasn't moved to the "done" queue yet. */ + if (preview_taskdata->preview) { + MEM_freeN(preview_taskdata->preview); + } + MEM_freeN(preview_taskdata); } -- cgit v1.2.3