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 {...@@ -18968,22 +18968,23 @@ fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {
18968 .adhoc_inferred_error_set_type => {18968 .adhoc_inferred_error_set_type => {
18969 const ies = sema.fn_ret_ty_ies.?;18969 const ies = sema.fn_ret_ty_ies.?;
18970 assert(ies.func == .none);18970 assert(ies.func == .none);
18971 try addToInferredErrorSetPtr(mod, ies, sema.typeOf(uncasted_operand));18971 try sema.addToInferredErrorSetPtr(ies, sema.typeOf(uncasted_operand));
18972 },18972 },
18973 else => if (ip.isInferredErrorSetType(err_set_ty)) {18973 else => if (ip.isInferredErrorSetType(err_set_ty)) {
18974 const ies = sema.fn_ret_ty_ies.?;18974 const ies = sema.fn_ret_ty_ies.?;
18975 assert(ies.func == sema.func_index);18975 assert(ies.func == sema.func_index);
18976 try addToInferredErrorSetPtr(mod, ies, sema.typeOf(uncasted_operand));18976 try sema.addToInferredErrorSetPtr(ies, sema.typeOf(uncasted_operand));
18977 },18977 },
18978 }18978 }
18979}18979}
1898018980
18981fn addToInferredErrorSetPtr(mod: *Module, ies: *InferredErrorSet, op_ty: Type) !void {18981fn addToInferredErrorSetPtr(sema: *Sema, ies: *InferredErrorSet, op_ty: Type) !void {
18982 const gpa = mod.gpa;18982 const arena = sema.arena;
18983 const mod = sema.mod;
18983 const ip = &mod.intern_pool;18984 const ip = &mod.intern_pool;
18984 switch (op_ty.zigTypeTag(mod)) {18985 switch (op_ty.zigTypeTag(mod)) {
18985 .ErrorSet => try ies.addErrorSet(op_ty, ip, gpa),18986 .ErrorSet => try ies.addErrorSet(op_ty, ip, arena),
18986 .ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(mod), ip, gpa),18987 .ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(mod), ip, arena),
18987 else => {},18988 else => {},
18988 }18989 }
18989}18990}
...@@ -29130,7 +29131,7 @@ fn coerceInMemoryAllowedErrorSets(...@@ -29130,7 +29131,7 @@ fn coerceInMemoryAllowedErrorSets(
29130 // We are trying to coerce an error set to the current function's29131 // We are trying to coerce an error set to the current function's
29131 // inferred error set.29132 // inferred error set.
29132 const dst_ies = sema.fn_ret_ty_ies.?;29133 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);
29134 return .ok;29135 return .ok;
29135 }29136 }
2913629137
...@@ -29140,7 +29141,7 @@ fn coerceInMemoryAllowedErrorSets(...@@ -29140,7 +29141,7 @@ fn coerceInMemoryAllowedErrorSets(
29140 if (dst_ies.func == dst_ies_func_index) {29141 if (dst_ies.func == dst_ies_func_index) {
29141 // We are trying to coerce an error set to the current function's29142 // We are trying to coerce an error set to the current function's
29142 // inferred error set.29143 // inferred error set.
29143 try dst_ies.addErrorSet(src_ty, ip, gpa);29144 try dst_ies.addErrorSet(src_ty, ip, sema.arena);
29144 return .ok;29145 return .ok;
29145 }29146 }
29146 }29147 }