authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-11 14:51:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-12 18:38:11-07:00
log56f2e5c5bc3267fa6c54d8fbc2295c5fa2a21571
treeafea9419eca940a548262a94dc5fd5138769854a
parent2eaef84ebe968224b0cf25206abf12ea1c5e0f5a

Sema: fix double-free on compile errors

when instantiating a generic function and an error occurs in the function prototype.

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

src/Sema.zig+3-1
......@@ -7096,6 +7096,7 @@ fn funcCommon(
70967096 if (param.ty.tag() == .generic_poison) is_generic = true;
70977097 }
70987098
7099 var destroy_fn_on_error = false;
70997100 const new_func: *Module.Fn = new_func: {
71007101 if (!has_body) break :new_func undefined;
71017102 if (sema.comptime_args_fn_inst == func_inst) {
......@@ -7103,9 +7104,10 @@ fn funcCommon(
71037104 sema.preallocated_new_func = null; // take ownership
71047105 break :new_func new_func;
71057106 }
7107 destroy_fn_on_error = true;
71067108 break :new_func try sema.gpa.create(Module.Fn);
71077109 };
7108 errdefer if (has_body) sema.gpa.destroy(new_func);
7110 errdefer if (destroy_fn_on_error) sema.gpa.destroy(new_func);
71097111
71107112 var maybe_inferred_error_set_node: ?*Module.Fn.InferredErrorSetListNode = null;
71117113 errdefer if (maybe_inferred_error_set_node) |node| sema.gpa.destroy(node);