CurtHagenlocher commented on code in PR #35996:
URL: https://github.com/apache/arrow/pull/35996#discussion_r1223337644
##########
csharp/src/Apache.Arrow/C/CArrowArrayImporter.cs:
##########
@@ -90,42 +96,49 @@ public static unsafe RecordBatch
ImportRecordBatch(CArrowArray* ptr, Schema sche
private sealed unsafe class ImportedArrowArray :
ImportedAllocationOwner
{
- private readonly CArrowArray* _cArray;
+ private readonly CArrowArray _cArray;
public ImportedArrowArray(CArrowArray* cArray)
{
if (cArray == null)
{
throw new ArgumentNullException(nameof(cArray));
}
- _cArray = cArray;
- if (_cArray->release == null)
+ if (cArray->release == null)
{
throw new ArgumentException("Tried to import an array that
has already been released.", nameof(cArray));
}
+ _cArray = *cArray;
+ cArray->release = null;
}
protected override void FinalRelease()
{
- if (_cArray->release != null)
+ if (_cArray.release != null)
{
- _cArray->release(_cArray);
+ fixed (CArrowArray* cArray = &_cArray)
+ {
+ cArray->release(cArray);
+ }
Review Comment:
Without the "fixed", in theory the GC could move the current object while
we're inside the call. This would change the location of the embedded struct.
--
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]