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.
This commit is contained in:
Travis Staloch 2025-07-14 16:35:23 -07:00 committed by Andrew Kelley
parent 4f5fa959aa
commit 294db62d92

View File

@ -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);
}