Skip to content

fix: Set an exported array's release callback only once the export has succeeded (#547) - #549

Merged
CurtHagenlocher merged 1 commit into
apache:maint-23.xfrom
CurtHagenlocher:c-export-failure-23.x
Dec 5, 2026
Merged

CurtHagenlocher merged 1 commit into
apache:maint-23.xfrom
CurtHagenlocher:c-export-failure-23.x

Conversation

@CurtHagenlocher

Copy link
Copy Markdown
Contributor

Brings #547 to maint-23.x. maint-23.x has no transferOwnership overload of ExportRecordBatch, so the record batch test calls the two-argument overload.

…s succeeded (apache#547)

### What's changed?

`CArrowArrayExporter` set each struct's `release` callback and private
data as soon as it started converting it. If the export then failed, for
example because one of the array's buffers had already been disposed,
the exporter freed the memory it had allocated but left the caller's
struct with `release` set and pointing at that memory. Releasing the
struct afterwards, as `CArrowArray.Free` does, then read freed memory.
Each failure also kept a GC handle to the exporter's allocations.

- The array or record batch is converted in full first. Only then are
the release callbacks and private data set, children first.
- If the export fails, the caller's struct is left zeroed, which marks
it as released, and the exception is rethrown.

This covers `ExportArray`, `ExportRecordBatch`, and the stream and
device exporters that use them. The schema exporter already sets
`release` last, so it is unchanged.

### Testing

New tests in `CDataInterfaceDataTests` export a struct array with a
disposed child and a record batch with a disposed column (with and
without ownership transfer), check that the struct is left released, and
free it. Without the change they fail, and on net472 freeing the struct
crashed the test host. All of `Apache.Arrow.Tests`, including the
pyarrow C Data tests, passes on net8.0, net462 and net472.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_012dFdcrBz22tRjiyNwBd7VB

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

The record batch test calls ExportRecordBatch(batch, cArray), as there is no
transferOwnership overload here.

(cherry picked from commit 38ce7ee)

Claude-Session: https://claude.ai/code/session_012dFdcrBz22tRjiyNwBd7VB
@CurtHagenlocher
CurtHagenlocher merged commit 9840632 into apache:maint-23.x Dec 5, 2026
14 checks passed
@CurtHagenlocher
CurtHagenlocher deleted the c-export-failure-23.x branch December 5, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant