timmyb32r opened a new pull request, #11932:
URL: https://github.com/apache/arrow-rs/pull/11932
# Which issue does this PR close?
None — standalone bug fix.
# Rationale for this change
Repeated calls to `FFI_ArrowSchema::with_name` leak the previous name
allocation. For example, `.with_name("a")?.with_name("b")?` leaves the
allocation for `"a"` unreleased even after the schema is dropped.
# What changes are included in this PR?
Release the previous name allocation when replacing it.
Keep `with_name` safe by rejecting schemas that do not use this crate's
original release callback, since ownership of their name allocation cannot be
assumed.
# Are these changes tested?
Added a regression test in `src/ffi.rs` using a test allocator to verify
that the previous name is freed on replacement and the final name is freed when
the schema is dropped.
The regression test fails before the fix and passes afterward in debug and
release builds.
Additional tests cover rejection of empty schemas and foreign release
callbacks, including cleanup through the original producer's callback.
# Are there any significant user-facing changes?
`with_name` now returns an error for schemas without this crate's original
release callback. This includes empty schemas and schemas whose release
callback has been replaced or wrapped. The method remains safe.
# AI assistance
Codex identified the issue, generated the fix and regression tests, ran
validation, and drafted this PR description.
--
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]