Skip to content

Commit ec91674

Browse files
committed
Merge upstream back to our branch for the ArrayBuffer fix
2 parents 163e7fd + 6857a77 commit ec91674

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

worker.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,11 @@ func (w *Worker) LoadModule(scriptName string, code string, resolve ModuleResolv
244244
// Same as Send but for []byte. $recv callback will get an ArrayBuffer.
245245
func (w *Worker) SendBytes(msg []byte) error {
246246
msg_p := C.CBytes(msg)
247-
defer C.free(msg_p)
248247

248+
// C.CBytes allocates memory on the C heap that is used as the backing
249+
// storage for the ArrayBuffer given to javascript. v8 will free the buffer
250+
// as part of the ArrayBuffer garbage collection as we create the AB with
251+
// ArrayBufferCreationMode::kInternalized in worker_send_bytes.
249252
r := C.worker_send_bytes(w.worker.cWorker, msg_p, C.size_t(len(msg)))
250253
if r != 0 {
251254
errStr := C.GoString(C.worker_last_exception(w.worker.cWorker))

0 commit comments

Comments
 (0)