Fix T92740: Missing lock around the image CacheLimiter

A recent change exposed this long-standing race. Simply protect the
MEM_CacheLimiter with its lock now. Additionally, guard against
unmanaging an already destroyed cache handle.

Ref T92740, T92838
This commit is contained in:
Jesse Yurkovich 2021-11-04 20:58:32 -07:00 committed by Philipp Oeser
parent 0a6b6eb13b
commit ff5630b7fa
Notes: blender-bot 2023-02-14 06:55:40 +01:00
Referenced by issue #93479, 3.0 Potential candidates for corrective releases
Referenced by issue #92838, Crash when exceeding memory_cache_limit in the viewport
Referenced by issue #92740, BlenLib/ImageCache : Use after free
1 changed files with 6 additions and 1 deletions

View File

@ -122,7 +122,12 @@ static void moviecache_valfree(void *val)
PRINT("%s: cache '%s' free item %p buffer %p\n", __func__, cache->name, item, item->ibuf);
MEM_CacheLimiter_unmanage(item->c_handle);
BLI_mutex_lock(&limitor_lock);
if (item->c_handle) {
MEM_CacheLimiter_unmanage(item->c_handle);
}
BLI_mutex_unlock(&limitor_lock);
if (item->ibuf) {
IMB_freeImBuf(item->ibuf);
}