commit 294db62d926ef82f2beb86e7e5ddf8d69092864a (tree)
parent 4f5fa959aa80ce39828b8bf45098029ce818fda2
Author: Travis Staloch <1562827+travisstaloch@users.noreply.github.com>
Date: Mon, 14 Jul 2025 16:35:23 -0700
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.
Diffstat:
1 file changed, 2 insertions(+), 0 deletions(-)
diff --git 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);
}