authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-03-17 21:20:00+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-17 18:20:03-07:00
log79679be50ddfab04d34cb3dc412d4e5088de2126
tree1adf8cb526b44064f524d4bcf425a4446d381a6d
parent9dc9219b2feb5971ca5e86e0d0880233f28cf18c

sema: Fix memory leak

When a generic call evaluates to a generic type, the call will be re-generated. However, the old function was not freed before being re-generated, causing a memory leak. So rather than only returning an error, we first free the old value.

1 files changed, 1 insertions(+), 0 deletions(-)

src/Sema.zig+1
...@@ -5068,6 +5068,7 @@ fn instantiateGenericCall(...@@ -5068,6 +5068,7 @@ fn instantiateGenericCall(
5068 };5068 };
5069 const new_func_val = child_sema.resolveConstValue(&child_block, .unneeded, new_func_inst) catch unreachable;5069 const new_func_val = child_sema.resolveConstValue(&child_block, .unneeded, new_func_inst) catch unreachable;
5070 const new_func = new_func_val.castTag(.function).?.data;5070 const new_func = new_func_val.castTag(.function).?.data;
5071 errdefer new_func.deinit(gpa);
5071 assert(new_func == new_module_func);5072 assert(new_func == new_module_func);
50725073
5073 arg_i = 0;5074 arg_i = 0;