From: Jason Ekstrand Date: Sat, 6 Jun 2015 00:11:49 +0000 (-0700) Subject: vk/allocator: Avoid double-free in the bo pool X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ed2ca020f84213a5f0f7faf1115a0b6f545b3e62;p=mesa.git vk/allocator: Avoid double-free in the bo pool --- diff --git a/src/vulkan/allocator.c b/src/vulkan/allocator.c index 027108695fd..7fe7423b531 100644 --- a/src/vulkan/allocator.c +++ b/src/vulkan/allocator.c @@ -663,6 +663,13 @@ anv_bo_pool_finish(struct anv_bo_pool *pool) struct bo_pool_bo_link *link = PFL_PTR(pool->free_list); while (link != NULL) { struct bo_pool_bo_link link_copy = VG_NOACCESS_READ(link); + + /* The anv_gem_m[un]map() functions are also valgrind-safe so they + * act as an alloc/free. In order to avoid a double-free warning, we + * need to mark thiss as malloc'd before we unmap it. + */ + VG(VALGRIND_MALLOCLIKE_BLOCK(link_copy.bo.map, pool->bo_size, 0, false)); + anv_gem_munmap(link_copy.bo.map, pool->bo_size); anv_gem_close(pool->device, link_copy.bo.gem_handle); link = link_copy.next; @@ -700,10 +707,10 @@ anv_bo_pool_alloc(struct anv_bo_pool *pool, struct anv_bo *bo) return vk_error(VK_ERROR_MEMORY_MAP_FAILED); } - /* We don't need to call VALGRIND_MALLOCLIKE_BLOCK here because valgrind - * already picks up on the gem_mmap and treats that as a malloc. If we - * really want to be pedantic we could do a VALGRIND_FREELIKE_BLOCK - * right after the mmap, but there's no good reason. + /* We don't need to call VALGRIND_MALLOCLIKE_BLOCK here because gem_mmap + * calls it for us. If we really want to be pedantic we could do a + * VALGRIND_FREELIKE_BLOCK right after the mmap, but there's no good + * reason. */ *bo = new_bo;