aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-07-11 14:51:22 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-07-12 18:38:11 -0700
commit56f2e5c5bc3267fa6c54d8fbc2295c5fa2a21571 (patch)
treeafea9419eca940a548262a94dc5fd5138769854a /src/Sema.zig
parent2eaef84ebe968224b0cf25206abf12ea1c5e0f5a (diff)
downloadzig-56f2e5c5bc3267fa6c54d8fbc2295c5fa2a21571.tar.gz
zig-56f2e5c5bc3267fa6c54d8fbc2295c5fa2a21571.zip
Sema: fix double-free on compile errors
when instantiating a generic function and an error occurs in the function prototype.
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index f7d8aef12d..550f51d7c5 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -7096,6 +7096,7 @@ fn funcCommon(
if (param.ty.tag() == .generic_poison) is_generic = true;
}
+ var destroy_fn_on_error = false;
const new_func: *Module.Fn = new_func: {
if (!has_body) break :new_func undefined;
if (sema.comptime_args_fn_inst == func_inst) {
@@ -7103,9 +7104,10 @@ fn funcCommon(
sema.preallocated_new_func = null; // take ownership
break :new_func new_func;
}
+ destroy_fn_on_error = true;
break :new_func try sema.gpa.create(Module.Fn);
};
- errdefer if (has_body) sema.gpa.destroy(new_func);
+ errdefer if (destroy_fn_on_error) sema.gpa.destroy(new_func);
var maybe_inferred_error_set_node: ?*Module.Fn.InferredErrorSetListNode = null;
errdefer if (maybe_inferred_error_set_node) |node| sema.gpa.destroy(node);