jbonofre opened a new pull request, #1545:
URL: https://github.com/apache/arrow-java/pull/1545

   ## 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 `increment` without checking for overflow, so a retain 
past `Integer.MAX_VALUE` wraps 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 checks `increment <= Integer.MAX_VALUE - originalReferenceCount` before 
the compare-and-set. A retain that would overflow throws 
`IllegalArgumentException` and leaves the count unchanged, like a retain on a 
released ledger.
   
   Two smaller changes in the same code:
   
   - In debug mode, the retain event is now recorded in the ledger history 
after the compare-and-set succeeds instead of before the check. A rejected 
retain on a released ledger no longer shows up in the history as if it had 
revived the ledger.
   - Both error messages now include the increment and the current count. A 
retain on an over-released ledger (count -1) is no longer reported the same as 
one at 0.
   
   `testRetainOnReleasedBufferIsRejectedRepeatedly` now only expects `setInt` 
on a released buffer to throw when bounds checking is enabled. `ArrowBuf` does 
not check the reference count otherwise, so with 
`ARROW_ENABLE_UNSAFE_MEMORY_ACCESS=true` the test wrote into freed memory 
instead of throwing.
   
   The new `testRetainRejectsReferenceCountOverflow` fails on `main` at its 
first `assertThrows`. The `memory-core`, `memory-unsafe` and `memory-netty` 
suites pass.
   
   Closes #1544.
   


-- 
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]

Reply via email to