fix: Don't nullify release callback for schemas#6
Merged
Conversation
peasee
commented
Oct 21, 2025
phillipleblanc
approved these changes
Oct 21, 2025
mach-kernel
pushed a commit
that referenced
this pull request
Oct 28, 2025
fix: Don't nullify release callback for schemas
mach-kernel
pushed a commit
that referenced
this pull request
Oct 28, 2025
fix: Don't nullify release callback for schemas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🗣 Description
FactoryGetSchemaCAPI factory. This ensures that, when bound to anArrowSchemaWrapper, the schema is released when destructed. Previously, the schema would never be released because the release function was overridden.duckdb_arrow_array_scanwork. The Arrow C Stream Specification defines that schema lifetimes can be independent from the stream, and can be released individually, so I am not sure what the original comment was referring to.duckdb-rscould never release the schema itself even if it wanted too, because it never had a handle to the schema to begin with. The schema was only ever retrieved byduckdbcode, through theFactoryGetSchemafunction from the stream.PrivateDatato ensure the schema is released when thePrivateDatais deleted as it stores the direct arrow schema. Destroying aPrivateDatawithout releasing the schema would result in a leak.This PR breaks the functionality of
duckdb_arrow_array_scan:duckdb_arrow_array_scandoes some clobbering of the release functions and lifecycles, and it results in the arrow schema being freed when theArrowSchemaWrapperis destroyed. TheGetSchemafunction that this stream implements does not create a new instance of an arrow schema, but it instead returns a pointer to an existing arrow schema which the user supplies as a function input.GetSchemacall, when theArrowSchemaWrapperis destroyed it results in the underlying shared schema being released. The nextGetSchemacall will then return the same pointer to the released schema, whose memory doesn't exist anymore.duckdb_arrow_array_scannow segfaults, captured by the failing tests. We'll merge this as-is though, as datafusion-table-providers does not useduckdb_arrow_array_scan. A correct fix would be updating theGetSchemafactory forduckdb_arrow_array_scanto somehow return a clone of the original schema, but persist a release function so these clones get released.