Copilot commented on code in PR #152:
URL: https://github.com/apache/arrow-swift/pull/152#discussion_r3007774385


##########
Tests/ArrowTests/ArrayTests.swift:
##########
@@ -344,10 +411,25 @@ final class ArrayTests: XCTestCase { // 
swiftlint:disable:this type_body_length
     }
 
     func checkHolderForType(_ checkType: ArrowType) throws {
-        let buffers = [ArrowBuffer(length: 0, capacity: 0,
-                                   rawPointer: 
UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: .zero)),
-                       ArrowBuffer(length: 0, capacity: 0,
-                                   rawPointer: 
UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: .zero))]
+        let emptyPtr = UnsafeMutableRawPointer.allocate(byteCount: 0, 
alignment: .zero)
+        let buffers: [ArrowBuffer]
+        switch checkType.info {
+        case .variableInfo:
+            let offsetPtr = UnsafeMutableRawPointer.allocate(byteCount: 
MemoryLayout<Int32>.stride, alignment: 4)
+            offsetPtr.storeBytes(of: Int32(0), as: Int32.self)
+            buffers = [
+                ArrowBuffer(length: 0, capacity: 0, rawPointer: emptyPtr),
+                ArrowBuffer(length: 1, capacity: 
UInt(MemoryLayout<Int32>.stride), rawPointer: offsetPtr),
+                ArrowBuffer(length: 0, capacity: 0,
+                            rawPointer: 
UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: .zero))
+            ]
+        default:
+            buffers = [
+                ArrowBuffer(length: 0, capacity: 0, rawPointer: emptyPtr),
+                ArrowBuffer(length: 0, capacity: 0,
+                            rawPointer: 
UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: .zero))
+            ]
+        }

Review Comment:
   `checkHolderForType` reuses the same `emptyPtr` for multiple `ArrowBuffer` 
instances that all default to `isMemoryOwner: true`. When these buffers are 
deallocated this will double-free the same pointer and can crash tests / 
trigger undefined behavior. Allocate a distinct empty pointer per buffer (e.g. 
use `ArrowBuffer.createEmptyBuffer()`), or mark shared buffers with 
`isMemoryOwner: false` so only one owner deallocates.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to