From b43bcb05a172e44bc2bd4dda5eac9397a54fa2f0 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Thu, 6 Aug 2020 11:13:06 +0300 Subject: [PATCH] anv: fix incorrect realloc failure handling We don't want to leak in case of failure. Signed-off-by: Lionel Landwerlin Reported-by: Ivan Briano Fixes: 246261f0addf ("anv: prepare the driver for delayed submissions") Fixes: 34f32a6d6648 ("anv: implement VK_KHR_timeline_semaphore") Reviewed-by: Ivan Briano Part-of: --- src/intel/vulkan/anv_queue.c | 38 +++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c index 7ba64af54c4..0ca71b17964 100644 --- a/src/intel/vulkan/anv_queue.c +++ b/src/intel/vulkan/anv_queue.c @@ -405,14 +405,14 @@ anv_queue_submit_add_fence_bo(struct anv_queue_submit *submit, { if (submit->fence_bo_count >= submit->fence_bo_array_length) { uint32_t new_len = MAX2(submit->fence_bo_array_length * 2, 64); - - submit->fence_bos = + uintptr_t *new_fence_bos = vk_realloc(submit->alloc, submit->fence_bos, new_len * sizeof(*submit->fence_bos), 8, submit->alloc_scope); - if (submit->fence_bos == NULL) + if (new_fence_bos == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); + submit->fence_bos = new_fence_bos; submit->fence_bo_array_length = new_len; } @@ -433,14 +433,14 @@ anv_queue_submit_add_syncobj(struct anv_queue_submit* submit, if (submit->fence_count >= submit->fence_array_length) { uint32_t new_len = MAX2(submit->fence_array_length * 2, 64); - - submit->fences = + struct drm_i915_gem_exec_fence *new_fences = vk_realloc(submit->alloc, submit->fences, new_len * sizeof(*submit->fences), 8, submit->alloc_scope); - if (submit->fences == NULL) + if (new_fences == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); + submit->fences = new_fences; submit->fence_array_length = new_len; } @@ -483,21 +483,24 @@ anv_queue_submit_add_timeline_wait(struct anv_queue_submit* submit, { if (submit->wait_timeline_count >= submit->wait_timeline_array_length) { uint32_t new_len = MAX2(submit->wait_timeline_array_length * 2, 64); - - submit->wait_timelines = + struct anv_timeline **new_wait_timelines = vk_realloc(submit->alloc, submit->wait_timelines, new_len * sizeof(*submit->wait_timelines), 8, submit->alloc_scope); - if (submit->wait_timelines == NULL) + if (new_wait_timelines == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); - submit->wait_timeline_values = + submit->wait_timelines = new_wait_timelines; + + uint64_t *new_wait_timeline_values = vk_realloc(submit->alloc, submit->wait_timeline_values, new_len * sizeof(*submit->wait_timeline_values), 8, submit->alloc_scope); - if (submit->wait_timeline_values == NULL) + if (new_wait_timeline_values == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); + submit->wait_timeline_values = new_wait_timeline_values; + submit->wait_timeline_array_length = new_len; } @@ -519,21 +522,24 @@ anv_queue_submit_add_timeline_signal(struct anv_queue_submit* submit, if (submit->signal_timeline_count >= submit->signal_timeline_array_length) { uint32_t new_len = MAX2(submit->signal_timeline_array_length * 2, 64); - - submit->signal_timelines = + struct anv_timeline **new_signal_timelines = vk_realloc(submit->alloc, submit->signal_timelines, new_len * sizeof(*submit->signal_timelines), 8, submit->alloc_scope); - if (submit->signal_timelines == NULL) + if (new_signal_timelines == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); - submit->signal_timeline_values = + submit->signal_timelines = new_signal_timelines; + + uint64_t *new_signal_timeline_values = vk_realloc(submit->alloc, submit->signal_timeline_values, new_len * sizeof(*submit->signal_timeline_values), 8, submit->alloc_scope); - if (submit->signal_timeline_values == NULL) + if (new_signal_timeline_values == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); + submit->signal_timeline_values = new_signal_timeline_values; + submit->signal_timeline_array_length = new_len; } -- 2.30.2