From e2e44661c2e5bb96ef70df4e6e68b05e19ec36c7 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 22 Jul 2023 22:20:10 -0700 Subject: Explicitly ref/unref blobs before extracting the value (#3755) * Explicitly ref/unref blobs before extracting the value * :scissors: --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- src/bun.js/webcore/blob.zig | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/bun.js/webcore/blob.zig') diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index e81d1f8f6..7036babfb 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -790,6 +790,10 @@ pub const Blob = struct { } } + var input_store: ?*Store = if (path_or_blob == .blob) path_or_blob.blob.store else null; + if (input_store) |st| st.ref(); + defer if (input_store) |st| st.deref(); + var needs_async = false; if (data.isString()) { @@ -973,6 +977,17 @@ pub const Blob = struct { }; }; + var destination_store = destination_blob.store; + if (destination_store) |store| { + store.ref(); + } + + defer { + if (destination_store) |store| { + store.deref(); + } + } + return writeFileWithSourceDestination(ctx, &source_blob, &destination_blob); } @@ -2503,6 +2518,9 @@ pub const Blob = struct { globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame, ) callconv(.C) JSC.JSValue { + var store = this.store; + if (store) |st| st.ref(); + defer if (store) |st| st.deref(); return promisified(this.toString(globalThis, .clone), globalThis); } @@ -2510,6 +2528,9 @@ pub const Blob = struct { this: *Blob, globalObject: *JSC.JSGlobalObject, ) JSC.JSValue { + var store = this.store; + if (store) |st| st.ref(); + defer if (store) |st| st.deref(); return promisified(this.toString(globalObject, .transfer), globalObject); } @@ -2518,6 +2539,10 @@ pub const Blob = struct { globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame, ) callconv(.C) JSC.JSValue { + var store = this.store; + if (store) |st| st.ref(); + defer if (store) |st| st.deref(); + return promisified(this.toJSON(globalThis, .share), globalThis); } @@ -2525,6 +2550,10 @@ pub const Blob = struct { this: *Blob, globalThis: *JSC.JSGlobalObject, ) JSC.JSValue { + var store = this.store; + if (store) |st| st.ref(); + defer if (store) |st| st.deref(); + return promisified(this.toArrayBuffer(globalThis, .transfer), globalThis); } @@ -2533,6 +2562,9 @@ pub const Blob = struct { globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame, ) callconv(.C) JSValue { + var store = this.store; + if (store) |st| st.ref(); + defer if (store) |st| st.deref(); return promisified(this.toArrayBuffer(globalThis, .clone), globalThis); } @@ -2541,6 +2573,10 @@ pub const Blob = struct { globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame, ) callconv(.C) JSValue { + var store = this.store; + if (store) |st| st.ref(); + defer if (store) |st| st.deref(); + return promisified(this.toFormData(globalThis, .temporary), globalThis); } -- cgit v1.2.3