Repository navigation
Conversation
Check that the increment fits before the compare-and-set, so a retain that would wrap the count negative is rejected and leaves it unchanged. Record retains in the debug history only once they take effect, and include the increment and the current count in the error messages. Only assert that setInt on a released buffer throws when bounds checking is enabled, since ArrowBuf does not check the reference count otherwise. Closes apache#1544.
lidavidm
approved these changes
Dec 3, 2026
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.
What's Changed
Follow-up to #1543, which made
BufferLedger.retain(int)check the count before its compare-and-set so that a released ledger is never revived.That loop still adds
incrementwithout checking for overflow, so a retain pastInteger.MAX_VALUEwraps the count negative. A negative count can never be released back to 0, so the memory leaks.ArrowBuf.ensureAccessible()only rejects a count of exactly 0, so the buffer also stays accessible. The loop now also checksincrement <= Integer.MAX_VALUE - originalReferenceCountbefore the compare-and-set. A retain that would overflow throwsIllegalArgumentExceptionand leaves the count unchanged, like a retain on a released ledger.Two smaller changes in the same code:
testRetainOnReleasedBufferIsRejectedRepeatedlynow only expectssetInton a released buffer to throw when bounds checking is enabled.ArrowBufdoes not check the reference count otherwise, so withARROW_ENABLE_UNSAFE_MEMORY_ACCESS=truethe test wrote into freed memory instead of throwing.The new
testRetainRejectsReferenceCountOverflowfails onmainat its firstassertThrows. Thememory-core,memory-unsafeandmemory-nettysuites pass.Closes #1544.