Skip to content

fix(arrow/array): Resize(0) on non-empty builder causes memory leak - #995

Merged
zeroshade merged 2 commits into
apache:mainfrom
serramatutu:serramatutu/Resize-leak
Jul 24, 2026
Merged

fix(arrow/array): Resize(0) on non-empty builder causes memory leak#995
zeroshade merged 2 commits into
apache:mainfrom
serramatutu:serramatutu/Resize-leak

Conversation

@serramatutu

@serramatutu serramatutu commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

I found a memory leak while working on the JSON nullable parity PR. It's triggered whenever a non-empty builder gets resized to zero.

This memory leak can be achieved with public APIs only (Append and Resize), meaning it's an actual bug in the public API and not a misuse of internal APIs where I didn't check for an invariant.

In the specific case of the JSON PR, whenever we found an error in the first row that would call Resize(-1), which in turn calls Resize(0) on all the previous fields, and the bug gets triggered.

You can checkout to each commit to see the test failing then passing after the fix.

What changes are included in this PR?

  • A new unit test to repro the memory leak.
  • The fix: always respect minBuilderCapacity when calling Resize()

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

@serramatutu
serramatutu marked this pull request as ready for review July 24, 2026 11:29
@serramatutu
serramatutu requested a review from zeroshade as a code owner July 24, 2026 11:29
@serramatutu serramatutu changed the title fix(arrow/array): Append then Resize causes memory leak on numeric builders fix(arrow/array): Resize(0) on non-empty builder causes memory leak Jul 24, 2026
@zeroshade
zeroshade merged commit 3886c0a into apache:main Jul 24, 2026
23 checks passed
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.

2 participants