vulkan/shader_module: Fix the lifetime of temporary shader modules

The vk_shader_module_handle_from_nir() macro was constructing a
temporary vk_shader_module and passing it through
vk_shader_module_to_handle().  Since this is a function and not a macro,
it means that the lifetime of the temporary vk_shader_module will end
once the to_handle() function is called.  Technically, this is a
use-after-free.  I really don't know why no one has been bitten by this
yet....

Fixes: a41e98ddca "vk/util: add a util macro for initializing stack..."
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13101>
This commit is contained in:
Jason Ekstrand 2021-09-29 08:15:24 -05:00 committed by Marge Bot
parent 2b826582d8
commit 24637a6579

View file

@ -46,7 +46,7 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(vk_shader_module, base, VkShaderModule,
/* this should only be used for stack-allocated, temporary objects */
#define vk_shader_module_handle_from_nir(_nir) \
vk_shader_module_to_handle(&(struct vk_shader_module) { \
((VkShaderModule)(uintptr_t)&(struct vk_shader_module) { \
.base.type = VK_OBJECT_TYPE_SHADER_MODULE, \
.nir = _nir, \
})