aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Staloch <1562827+travisstaloch@users.noreply.github.com>2025-07-14 16:35:23 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-07-15 08:49:54 +0200
commit294db62d926ef82f2beb86e7e5ddf8d69092864a (patch)
tree3d47be43b54702dbee00bb90ff247f027748b8a2
parent4f5fa959aa80ce39828b8bf45098029ce818fda2 (diff)
downloadzig-294db62d926ef82f2beb86e7e5ddf8d69092864a.tar.gz
zig-294db62d926ef82f2beb86e7e5ddf8d69092864a.zip
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.
-rw-r--r--lib/std/Io/Writer.zig2
1 files changed, 2 insertions, 0 deletions
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);
}