Copilot commented on code in PR #547:
URL: https://github.com/apache/arrow-dotnet/pull/547#discussion_r4808911803
##########
src/Apache.Arrow/C/CArrowArrayExporter.cs:
##########
@@ -257,6 +273,25 @@ private unsafe static void ReleaseArray(CArrowArray*
cArray)
cArray->release = default;
}
+ /// <summary>
+ /// Sets the release callback of <paramref name="cArray"/> and
everything under it, once
+ /// conversion has succeeded. Until then nothing refers to the owner,
so a failed export
+ /// leaves nothing for a consumer to release.
+ /// </summary>
+ private unsafe static void SetRelease(ExportedAllocationOwner
sharedOwner, CArrowArray* cArray)
+ {
+ for (long i = 0; i < cArray->n_children; i++)
+ {
+ SetRelease(sharedOwner, cArray->children[i]);
+ }
+ if (cArray->dictionary != null)
+ {
+ SetRelease(sharedOwner, cArray->dictionary);
+ }
+ cArray->private_data = MakePrivateData(sharedOwner);
Review Comment:
If `GCHandle.Alloc` throws during `SetRelease`, handles already installed on
earlier children are leaked: both export catch blocks clear the root, and
disposing the owner frees the child structs without freeing those handles. The
leaked handles permanently root the disposed owner. Roll back every installed
handle before clearing the root, keeping the owner's allocations alive until
rollback finishes.
--
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]