From 9fd1d47aa0f19fac30d29e6ae40ed0383c1930ee Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Sun, 13 Nov 2022 22:30:25 -0800 Subject: [PATCH] intel/compiler: Fix dynarray usage in intel_clc The code builds up the dynamic array of objects (spirv_objs) and collect pointers to each of them into another dynamic array (spirv_ptr_objs). If the growth of the first array cause a reallocation, it is possible that the previous pointers end up invalid. Fixes: 77e929a5273 ("intel/clc: allow multiple CL files to be compiled together") Reviewed-by: Lionel Landwerlin Reviewed-by: Jordan Justen Part-of: --- src/intel/compiler/intel_clc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/intel/compiler/intel_clc.c b/src/intel/compiler/intel_clc.c index 4a56eef2df1..c1887c130a7 100644 --- a/src/intel/compiler/intel_clc.c +++ b/src/intel/compiler/intel_clc.c @@ -450,8 +450,10 @@ int main(int argc, char **argv) ralloc_free(mem_ctx); return 1; } + } - util_dynarray_append(&spirv_ptr_objs, struct clc_binary *, spirv_out); + util_dynarray_foreach(&spirv_objs, struct clc_binary, p) { + util_dynarray_append(&spirv_ptr_objs, struct clc_binary *, p); } /* The SPIRV-Tools linker started checking that all modules have the same