diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index c7b72a46c22562..130318d7c190ef 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -823,12 +823,13 @@ pub const Listener = struct { global.throwInvalidArguments("hostname pattern expects a string", .{}); return .zero; } - const host_str = hostname.toSliceZ( + const host_str = hostname.toSlice( global, bun.default_allocator, ); defer host_str.deinit(); - const server_name = host_str.sliceZ(); + const server_name = bun.default_allocator.dupeZ(u8, host_str.slice()) catch bun.outOfMemory(); + defer bun.default_allocator.free(server_name); if (server_name.len == 0) { global.throwInvalidArguments("hostname pattern cannot be empty", .{}); return .zero; diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 5edce707d64e71..a00235d193da26 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -804,8 +804,8 @@ pub const ZigString = extern struct { pub fn toSliceZ(this: ZigString, allocator: std.mem.Allocator) Slice { if (this.len == 0) return Slice.empty; - // if is 16 bit or dont has a null terminator - if (is16Bit(&this) or this._unsafe_ptr_do_not_use[this.len] != 0) { + + if (is16Bit(&this)) { const buffer = this.toOwnedSliceZ(allocator) catch unreachable; return Slice{ .ptr = buffer.ptr,