Skip to content

GH-1205: Fix byte-array element leak in FromSchemaByteArray#1249

Open
PG1204 wants to merge 1 commit into
apache:mainfrom
PG1204:gh-1205-fix-schema-bytearray-leak
Open

GH-1205: Fix byte-array element leak in FromSchemaByteArray#1249
PG1204 wants to merge 1 commit into
apache:mainfrom
PG1204:gh-1205-fix-schema-bytearray-leak

Conversation

@PG1204

@PG1204 PG1204 commented Jul 24, 2026

Copy link
Copy Markdown

What's Changed

FromSchemaByteArray() in dataset/src/main/cpp/jni_util.cc acquires the Java byte-array elements via GetByteArrayElements(), but the matching ReleaseByteArrayElements() call was only reached on the success path.
When arrow::ipc::ReadSchema() failed, ARROW_ASSIGN_OR_RAISE returned early and skipped the release, leaking the pinned/copied array buffer on every call with malformed or incompatible serialized schema bytes (e.g. via the public createDataset() method).

This change releases the elements through an RAII guard (a std::unique_ptr with a custom deleter) so they are always freed on every exit path - success or error, and remains correct if additional early returns are
added in the future.

Closes #1205.

@github-actions

Copy link
Copy Markdown

Thank you for opening a pull request!

Please label the PR with one or more of:

  • bug-fix
  • chore
  • dependencies
  • documentation
  • enhancement

Also, add the 'breaking-change' label if appropriate.

See CONTRIBUTING.md for details.

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.

Byte-array elements leak in FromSchemaByteArray()

1 participant