Commit dfab1aff6d69fb0801cb60dd0021db2c1272bc4a

Thomas de Grivel 2023-12-21T03:02:52

fix ic3 array double free

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/libc3/env.c b/libc3/env.c
index 236639b..5f4db79 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -118,6 +118,8 @@ bool env_eval_array (s_env *env, const s_array *array, s_array *dest)
   array_init_copy(&tmp, array);
   item_size = tmp.dimensions[tmp.dimension - 1].item_size;
   if (! tmp.data && array->tags) {
+    if (! sym_to_init_cast(tmp.type, &init_cast))
+      return false;
     tmp.data = tmp.data_free = calloc(tmp.dimensions[0].count,
                                       tmp.dimensions[0].item_size);
     if (! tmp.data) {
@@ -125,7 +127,6 @@ bool env_eval_array (s_env *env, const s_array *array, s_array *dest)
       assert(! "env_eval_array: failed to allocate memory");
       return false;
     }
-    if (! sym_to_init_cast(tmp.type, &init_cast))
     data = tmp.data;
     tag = tmp.tags;
     i = 0;