authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-22 15:50:02+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-23 12:48:08-07:00
log5f4c9a7449bf891fdc0f2bb2e1f9c205031b2237
tree8da6fcee8b34197288401f53328278c387e49949
parentb00287175c044682ea025805de05a6ac26a42771

sema: fix mem leaks in inferred error set handling


1 files changed, 9 insertions(+), 8 deletions(-)

src/Sema.zig+9-8
......@@ -18968,22 +18968,23 @@ fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {
1896818968 .adhoc_inferred_error_set_type => {
1896918969 const ies = sema.fn_ret_ty_ies.?;
1897018970 assert(ies.func == .none);
18971 try addToInferredErrorSetPtr(mod, ies, sema.typeOf(uncasted_operand));
18971 try sema.addToInferredErrorSetPtr(ies, sema.typeOf(uncasted_operand));
1897218972 },
1897318973 else => if (ip.isInferredErrorSetType(err_set_ty)) {
1897418974 const ies = sema.fn_ret_ty_ies.?;
1897518975 assert(ies.func == sema.func_index);
18976 try addToInferredErrorSetPtr(mod, ies, sema.typeOf(uncasted_operand));
18976 try sema.addToInferredErrorSetPtr(ies, sema.typeOf(uncasted_operand));
1897718977 },
1897818978 }
1897918979}
1898018980
18981fn addToInferredErrorSetPtr(mod: *Module, ies: *InferredErrorSet, op_ty: Type) !void {
18982 const gpa = mod.gpa;
18981fn addToInferredErrorSetPtr(sema: *Sema, ies: *InferredErrorSet, op_ty: Type) !void {
18982 const arena = sema.arena;
18983 const mod = sema.mod;
1898318984 const ip = &mod.intern_pool;
1898418985 switch (op_ty.zigTypeTag(mod)) {
18985 .ErrorSet => try ies.addErrorSet(op_ty, ip, gpa),
18986 .ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(mod), ip, gpa),
18986 .ErrorSet => try ies.addErrorSet(op_ty, ip, arena),
18987 .ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(mod), ip, arena),
1898718988 else => {},
1898818989 }
1898918990}
......@@ -29130,7 +29131,7 @@ fn coerceInMemoryAllowedErrorSets(
2913029131 // We are trying to coerce an error set to the current function's
2913129132 // inferred error set.
2913229133 const dst_ies = sema.fn_ret_ty_ies.?;
29133 try dst_ies.addErrorSet(src_ty, ip, gpa);
29134 try dst_ies.addErrorSet(src_ty, ip, sema.arena);
2913429135 return .ok;
2913529136 }
2913629137
......@@ -29140,7 +29141,7 @@ fn coerceInMemoryAllowedErrorSets(
2914029141 if (dst_ies.func == dst_ies_func_index) {
2914129142 // We are trying to coerce an error set to the current function's
2914229143 // inferred error set.
29143 try dst_ies.addErrorSet(src_ty, ip, gpa);
29144 try dst_ies.addErrorSet(src_ty, ip, sema.arena);
2914429145 return .ok;
2914529146 }
2914629147 }