Skip to content

Commit

Permalink
tu: Fix potential alloc of 0 size
Browse files Browse the repository at this point in the history
We can end up calling vk_multialloc_alloc with 0 size when
`attachment_count` is 0 and `clearValueCount` is 0.

Addressed:
```
Direct leak of 1 byte(s) in 1 object(s) allocated from:
    #0 0x7faf033ee0 in __interceptor_malloc
       ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    waydroid#1 0x7fada5cc10 in vk_default_alloc ../src/vulkan/util/vk_alloc.c:26
    waydroid#2 0x7fac50b270 in vk_alloc ../src/vulkan/util/vk_alloc.h:48
    waydroid#3 0x7fac555040 in vk_multialloc_alloc
       ../src/vulkan/util/vk_alloc.h:234
    waydroid#4 0x7fac555040 in void
       tu_CmdBeginRenderPass2<(chip)7>(VkCommandBuffer_T*,
VkRenderPassBeginInfo const*, VkSubpassBeginInfo const*)
../src/freedreno/vulkan/tu_cmd_buffer.cc:4634
    waydroid#5 0x7fac900760 in vk_common_CmdBeginRenderPass
       ../src/vulkan/runtime/vk_render_pass.c:261
```
seen in:
dEQP-VK.robustness.robustness2.bind.notemplate.r32i.dontunroll.nonvolatile.uniform_texel_buffer.no_fmt_qual.len_252.samples_1.1d.frag

Fixes: 4cfd021 ("turnip: Save the renderpass's clear values in the cmdbuf state.")
Signed-off-by: Karmjit Mahil <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32057>
(cherry picked from commit c923eff742b83cc475d02ad57c538754db991c06)
  • Loading branch information
CreativeCylon authored and 1ace committed Nov 13, 2024
1 parent ed2af40 commit 969b7ba
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .pick_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@
"description": "tu: Fix potential alloc of 0 size",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "4cfd021e3f74fd75e7998cae5697a1ba598237d6",
"notes": null
Expand Down
4 changes: 2 additions & 2 deletions src/freedreno/vulkan/tu_cmd_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4414,8 +4414,8 @@ tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer,
const struct tu_image_view *, pass->attachment_count);
vk_multialloc_add(&ma, &cmd->state.clear_values, VkClearValue,
pRenderPassBegin->clearValueCount);
if (!vk_multialloc_alloc(&ma, &cmd->vk.pool->alloc,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT)) {
if (ma.size && !vk_multialloc_alloc(&ma, &cmd->vk.pool->alloc,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT)) {
vk_command_buffer_set_error(&cmd->vk, VK_ERROR_OUT_OF_HOST_MEMORY);
return;
}
Expand Down

0 comments on commit 969b7ba

Please sign in to comment.