mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
Fix thread safety issue in async fs functions file paths (#3964)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
@@ -829,6 +829,13 @@ pub const String = extern struct {
|
||||
return bun.strings.eqlLong(this.byteSlice(), value, true);
|
||||
}
|
||||
|
||||
extern fn BunString__toThreadSafe(this: *String) void;
|
||||
pub fn toThreadSafe(this: *String) void {
|
||||
if (this.tag == .WTFStringImpl) {
|
||||
BunString__toThreadSafe(this);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eql(this: String, other: String) bool {
|
||||
return this.toZigString().eql(other.toZigString());
|
||||
}
|
||||
@@ -838,6 +845,23 @@ pub const SliceWithUnderlyingString = struct {
|
||||
utf8: ZigString.Slice,
|
||||
underlying: String,
|
||||
|
||||
pub fn toThreadSafe(this: *SliceWithUnderlyingString) void {
|
||||
std.debug.assert(this.underlying.tag == .WTFStringImpl);
|
||||
|
||||
var orig = this.underlying.value.WTFStringImpl;
|
||||
this.underlying.toThreadSafe();
|
||||
if (this.underlying.value.WTFStringImpl != orig) {
|
||||
orig.deref();
|
||||
|
||||
if (this.utf8.allocator.get()) |allocator| {
|
||||
if (String.isWTFAllocator(allocator)) {
|
||||
this.utf8.deinit();
|
||||
this.utf8 = this.underlying.toUTF8(bun.default_allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit(this: SliceWithUnderlyingString) void {
|
||||
this.utf8.deinit();
|
||||
this.underlying.deref();
|
||||
|
||||
Reference in New Issue
Block a user