@@ -56,26 +56,24 @@ final class SMB2FileHandle: @unchecked Sendable {
5656 createOptions: CreateOptions = [ ] , on client: SMB2Client
5757 ) throws {
5858 var leaseData = opLock. leaseContext. map { Data ( $0. regions. joined ( ) ) } ?? . init( )
59-
60- let ( _, result) = try withExtendedLifetime ( leaseData) {
61- try path. replacingOccurrences ( of: " / " , with: " \\ " ) . withCString { path in
62- try client. async_await_pdu ( dataHandler: SMB2FileID . init) {
63- context, cbPtr -> UnsafeMutablePointer < smb2_pdu > ? in
64- var req = smb2_create_request ( )
65- req. requested_oplock_level = opLock. lockLevel
66- req. impersonation_level = impersonation. rawValue
67- req. desired_access = desiredAccess. rawValue
68- req. file_attributes = fileAttributes. rawValue
69- req. share_access = shareAccess. rawValue
70- req. create_disposition = createDisposition. rawValue
71- req. create_options = createOptions. rawValue
72- req. name = path
73- leaseData. withUnsafeMutableBytes {
74- req. create_context = $0. count > 0 ? $0. baseAddress? . assumingMemoryBound ( to: UInt8 . self) : nil
75- req. create_context_length = UInt32 ( $0. count)
76- }
77- return smb2_cmd_create_async ( context, & req, SMB2Client . generic_handler, cbPtr)
59+ defer { withExtendedLifetime ( leaseData) { } }
60+ let ( _, result) = try path. replacingOccurrences ( of: " / " , with: " \\ " ) . withCString { path in
61+ try client. async_await_pdu ( dataHandler: SMB2FileID . init) {
62+ context, cbPtr -> UnsafeMutablePointer < smb2_pdu > ? in
63+ var req = smb2_create_request ( )
64+ req. requested_oplock_level = opLock. lockLevel
65+ req. impersonation_level = impersonation. rawValue
66+ req. desired_access = desiredAccess. rawValue
67+ req. file_attributes = fileAttributes. rawValue
68+ req. share_access = shareAccess. rawValue
69+ req. create_disposition = createDisposition. rawValue
70+ req. create_options = createOptions. rawValue
71+ req. name = path
72+ leaseData. withUnsafeMutableBytes {
73+ req. create_context = $0. count > 0 ? $0. baseAddress? . assumingMemoryBound ( to: UInt8 . self) : nil
74+ req. create_context_length = UInt32 ( $0. count)
7875 }
76+ return smb2_cmd_create_async ( context, & req, SMB2Client . generic_handler, cbPtr)
7977 }
8078 }
8179 try self . init ( fileDescriptor: result. rawValue, on: client)
@@ -335,24 +333,23 @@ final class SMB2FileHandle: @unchecked Sendable {
335333 func fcntl< DataType: DataProtocol , R: DecodableResponse > (
336334 command: IOCtl . Command , args: DataType = Data ( )
337335 ) throws -> R {
338- try withExtendedLifetime ( args) { args in
339- var inputBuffer = [ UInt8] ( args)
340- return try inputBuffer. withUnsafeMutableBytes { buf in
341- var req = smb2_ioctl_request (
342- ctl_code: command. rawValue,
343- file_id: fileId. uuid,
344- input_offset: 0 , input_count: . init( buf. count) ,
345- max_input_response: 0 ,
346- output_offset: 0 , output_count: UInt32 ( client. maximumTransactionSize) ,
347- max_output_response: 65535 ,
348- flags: . init( SMB2_0_IOCTL_IS_FSCTL) ,
349- input: buf. baseAddress
350- )
351- return try client. async_await_pdu ( dataHandler: R . init) {
352- context, cbPtr -> UnsafeMutablePointer < smb2_pdu > ? in
353- smb2_cmd_ioctl_async ( context, & req, SMB2Client . generic_handler, cbPtr)
354- } . data
355- }
336+ defer { withExtendedLifetime ( args) { } }
337+ var inputBuffer = [ UInt8] ( args)
338+ return try inputBuffer. withUnsafeMutableBytes { buf in
339+ var req = smb2_ioctl_request (
340+ ctl_code: command. rawValue,
341+ file_id: fileId. uuid,
342+ input_offset: 0 , input_count: . init( buf. count) ,
343+ max_input_response: 0 ,
344+ output_offset: 0 , output_count: UInt32 ( client. maximumTransactionSize) ,
345+ max_output_response: 65535 ,
346+ flags: . init( SMB2_0_IOCTL_IS_FSCTL) ,
347+ input: buf. baseAddress
348+ )
349+ return try client. async_await_pdu ( dataHandler: R . init) {
350+ context, cbPtr -> UnsafeMutablePointer < smb2_pdu > ? in
351+ smb2_cmd_ioctl_async ( context, & req, SMB2Client . generic_handler, cbPtr)
352+ } . data
356353 }
357354 }
358355
0 commit comments