diff --git a/src/http/zlib.zig b/src/http/zlib.zig index 473bf236fe..b038db3e17 100644 --- a/src/http/zlib.zig +++ b/src/http/zlib.zig @@ -9,7 +9,7 @@ pub fn get(allocator: std.mem.Allocator) *MutableString { pub fn put(mutable: *MutableString) void { mutable.reset(); - var node: BufferPool.Node = @fieldParentPtr("data", mutable); + const node: *BufferPool.Node = @fieldParentPtr("data", mutable); node.release(); } diff --git a/src/paths/path_buffer_pool.zig b/src/paths/path_buffer_pool.zig index 4c950f8095..dd1cd77b65 100644 --- a/src/paths/path_buffer_pool.zig +++ b/src/paths/path_buffer_pool.zig @@ -13,7 +13,13 @@ fn PathBufferPoolT(comptime T: type) type { pub fn put(buffer: *const T) void { // there's no deinit function on T so @constCast is fine - var node: *Pool.Node = @alignCast(@fieldParentPtr("data", @constCast(buffer))); + const node: *Pool.Node = @alignCast(@fieldParentPtr("data", @constCast(buffer))); + // Validate the allocator pointer to catch use-after-free or invalid buffer pointers. + // A valid allocator should have non-null ptr and vtable fields. + if (comptime Environment.isDebug) { + bun.debugAssert(@intFromPtr(node.allocator.ptr) != 0); + bun.debugAssert(@intFromPtr(node.allocator.vtable) != 0); + } node.release(); }