From 294db62d926ef82f2beb86e7e5ddf8d69092864a Mon Sep 17 00:00:00 2001 From: Travis Staloch <1562827+travisstaloch@users.noreply.github.com> Date: Mon, 14 Jul 2025 16:35:23 -0700 Subject: [PATCH] memory safety fix for Io.Writer.Allocating.toOwnedSlice*() don't forget to save the list. this allows a `testing.checkAllAllocationFailures()` test to pass in one of my projects which newly failed since #24329 was merged. --- lib/std/Io/Writer.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/std/Io/Writer.zig b/lib/std/Io/Writer.zig index d931248c4d..e02e7e9440 100644 --- a/lib/std/Io/Writer.zig +++ b/lib/std/Io/Writer.zig @@ -2446,12 +2446,14 @@ pub const Allocating = struct { pub fn toOwnedSlice(a: *Allocating) error{OutOfMemory}![]u8 { var list = a.toArrayList(); + defer a.setArrayList(list); return list.toOwnedSlice(a.allocator); } pub fn toOwnedSliceSentinel(a: *Allocating, comptime sentinel: u8) error{OutOfMemory}![:sentinel]u8 { const gpa = a.allocator; var list = toArrayList(a); + defer a.setArrayList(list); return list.toOwnedSliceSentinel(gpa, sentinel); }