zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 5f4c9a7449bf891fdc0f2bb2e1f9c205031b2237 (tree)
parent b00287175c044682ea025805de05a6ac26a42771
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Fri, 22 Sep 2023 15:50:02 +0200

sema: fix mem leaks in inferred error set handling

Diffstat:
Msrc/Sema.zig | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -18968,22 +18968,23 @@ fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void { .adhoc_inferred_error_set_type => { const ies = sema.fn_ret_ty_ies.?; assert(ies.func == .none); - try addToInferredErrorSetPtr(mod, ies, sema.typeOf(uncasted_operand)); + try sema.addToInferredErrorSetPtr(ies, sema.typeOf(uncasted_operand)); }, else => if (ip.isInferredErrorSetType(err_set_ty)) { const ies = sema.fn_ret_ty_ies.?; assert(ies.func == sema.func_index); - try addToInferredErrorSetPtr(mod, ies, sema.typeOf(uncasted_operand)); + try sema.addToInferredErrorSetPtr(ies, sema.typeOf(uncasted_operand)); }, } } -fn addToInferredErrorSetPtr(mod: *Module, ies: *InferredErrorSet, op_ty: Type) !void { - const gpa = mod.gpa; +fn addToInferredErrorSetPtr(sema: *Sema, ies: *InferredErrorSet, op_ty: Type) !void { + const arena = sema.arena; + const mod = sema.mod; const ip = &mod.intern_pool; switch (op_ty.zigTypeTag(mod)) { - .ErrorSet => try ies.addErrorSet(op_ty, ip, gpa), - .ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(mod), ip, gpa), + .ErrorSet => try ies.addErrorSet(op_ty, ip, arena), + .ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(mod), ip, arena), else => {}, } } @@ -29130,7 +29131,7 @@ fn coerceInMemoryAllowedErrorSets( // We are trying to coerce an error set to the current function's // inferred error set. const dst_ies = sema.fn_ret_ty_ies.?; - try dst_ies.addErrorSet(src_ty, ip, gpa); + try dst_ies.addErrorSet(src_ty, ip, sema.arena); return .ok; } @@ -29140,7 +29141,7 @@ fn coerceInMemoryAllowedErrorSets( if (dst_ies.func == dst_ies_func_index) { // We are trying to coerce an error set to the current function's // inferred error set. - try dst_ies.addErrorSet(src_ty, ip, gpa); + try dst_ies.addErrorSet(src_ty, ip, sema.arena); return .ok; } }