diff --git a/src/node_file.cc b/src/node_file.cc index 1b56d2323c9526..92dd05462a3fd8 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -2482,11 +2482,10 @@ static void WriteString(const FunctionCallbackInfo& args) { } } else { // write(fd, string, pos, enc, undefined, ctx) CHECK_EQ(argc, 6); - FSReqWrapSync req_wrap_sync; - FSReqBase::FSReqBuffer stack_buffer; if (buf == nullptr) { if (!StringBytes::StorageSize(isolate, value, enc).To(&len)) return; + FSReqBase::FSReqBuffer stack_buffer; stack_buffer.AllocateSufficientStorage(len + 1); // StorageSize may return too large a char, so correct the actual length // by the write size @@ -2496,6 +2495,7 @@ static void WriteString(const FunctionCallbackInfo& args) { buf = *stack_buffer; } uv_buf_t uvbuf = uv_buf_init(buf, len); + FSReqWrapSync req_wrap_sync("write"); FS_SYNC_TRACE_BEGIN(write); int bytesWritten = SyncCall(env, args[5], &req_wrap_sync, "write", uv_fs_write, fd, &uvbuf, 1, pos);