Commit 294db62d92

Travis Staloch <1562827+travisstaloch@users.noreply.github.com>
2025-07-15 01:35:23
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.
1 parent 4f5fa95
Changed files (1)
lib
std
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);
     }