anv: fix use after free
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Wed, 8 May 2019 10:39:09 +0000 (11:39 +0100)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Wed, 8 May 2019 11:02:13 +0000 (12:02 +0100)
Once mem->bo is removed from the cache, it is likely to be freed.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Fixes: b80930a6fea075 ("anv: add support for VK_EXT_memory_budget")
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
src/intel/vulkan/anv_device.c

index d74116bd9c9e31b40d1b5fcec17e0d495443d555..e9f90604924e9007422f93ceba55f959b248d309 100644 (file)
@@ -2995,6 +2995,9 @@ void anv_FreeMemory(
    if (mem->map)
       anv_UnmapMemory(_device, _mem);
 
+   p_atomic_add(&pdevice->memory.heaps[mem->type->heapIndex].used,
+                -mem->bo->size);
+
    anv_bo_cache_release(device, &device->bo_cache, mem->bo);
 
 #if defined(ANDROID) && ANDROID_API_LEVEL >= 26
@@ -3002,9 +3005,6 @@ void anv_FreeMemory(
       AHardwareBuffer_release(mem->ahw);
 #endif
 
-   p_atomic_add(&pdevice->memory.heaps[mem->type->heapIndex].used,
-                -mem->bo->size);
-
    vk_free2(&device->alloc, pAllocator, mem);
 }