diff --git a/lib/std/heap/ArenaAllocator.zig b/lib/std/heap/ArenaAllocator.zig index ab5febfaadd081b9eefd6e17e4a8f4cf3d09e513..ad6c937c2346a1b6c4a3b97408d1a29fdf83c56f 100644 --- a/lib/std/heap/ArenaAllocator.zig +++ b/lib/std/heap/ArenaAllocator.zig @@ -358,14 +358,16 @@ fn alloc(ctx: *anyopaque, n: usize, alignment: Alignment, ret_addr: usize) ?[*]u const end_index = @atomicRmw(usize, &node.end_index, .Add, alignable, .acquire); // acquire any memory that may have been freed const aligned_index = alignedIndex(buf.ptr, end_index, alignment); assert(end_index + alignable >= aligned_index + n); - _ = @cmpxchgStrong( - usize, - &node.end_index, - end_index + alignable, - aligned_index + n, - .monotonic, // no need to release alignment padding; there's no one accessing it! - .monotonic, - ); + if (end_index + alignable != aligned_index + n) { + _ = @cmpxchgStrong( + usize, + &node.end_index, + end_index + alignable, + aligned_index + n, + .monotonic, // no need to release alignment padding; there's no one accessing it! + .monotonic, + ); + } if (aligned_index + n > buf.len) break :first_node .{ node, buf.len }; return buf[aligned_index..][0..n].ptr;