Copilot commented on code in PR #525:
URL: https://github.com/apache/arrow-dotnet/pull/525#discussion_r4793509384


##########
src/Apache.Arrow/Ipc/MessageBody.cs:
##########
@@ -32,9 +32,10 @@ internal sealed class MessageBody
         private readonly SharedMemoryOwner _owner;
 
         /// <param name="owner">The body's memory, of which this takes 
ownership.</param>
-        public MessageBody(IMemoryOwner<byte> owner)
+        /// <param name="lifetime">The lifetime of the allocator <paramref 
name="owner"/> came from.</param>
+        public MessageBody(IMemoryOwner<byte> owner, AllocationLifetime 
lifetime)
         {
-            _owner = new SharedMemoryOwner(owner);
+            _owner = new SharedMemoryOwner(owner, finalizeWhenUnreachable: 
lifetime == AllocationLifetime.Finalized);

Review Comment:
   This maps every value other than `Finalized` to `finalizeWhenUnreachable: 
false`, so an allocator that reports `Unspecified` (or an undefined enum value) 
is silently accepted for dictionary IPC bodies instead of being rejected. 
`ArrowBuffer` validates this lifetime, and the new allocator contract makes 
`Unspecified` invalid; validate it here too (ideally through a shared 
validator) before changing the ownership semantics.



##########
src/Apache.Arrow/ArrowBuffer.cs:
##########
@@ -33,9 +33,63 @@ public ArrowBuffer(ReadOnlyMemory<byte> data)
             _memory = data;
         }
 
+        // Not used by Arrow itself: internal callers state a lifetime 
explicitly. It is kept because
+        // applications call it through reflection, from before the public 
constructor below existed;
+        // it keeps the behaviour it always had.
         internal ArrowBuffer(IMemoryOwner<byte> memoryOwner)
+            : this(memoryOwner, AllocationLifetime.Finalized)

Review Comment:
   The PR description says the internal single-argument constructor is removed, 
but this change deliberately keeps it and preserves its historical behavior. 
Please either remove this constructor as described or update the PR 
description/API compatibility rationale so the public contract is not 
misleading.



##########
src/Apache.Arrow/ArrowBuffer.Builder.cs:
##########
@@ -227,7 +227,7 @@ internal ArrowBuffer Build(int byteSize, MemoryAllocator 
allocator = default)
                 IMemoryOwner<byte> memoryOwner = 
memoryAllocator.Allocate(bufferLength);
                 Memory.Slice(0, currentBytesLength).CopyTo(memoryOwner.Memory);
 
-                return new ArrowBuffer(memoryOwner);
+                return new ArrowBuffer(memoryOwner, memoryAllocator.Lifetime);

Review Comment:
   If `memoryAllocator.Lifetime` is `Unspecified` or another invalid enum 
value, the constructor throws here after `Allocate` has transferred no 
ownership, so `memoryOwner` is leaked. The new invalid-lifetime test exercises 
this path, but the owner should be disposed on validation failure (or the 
allocator lifetime should be validated before allocating).



-- 
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