Visitar URL original
Fix ByteBuf leak in BaseTransactionalMap.isEqual() by kalayciburak · Pull Request #7303 · redisson/redisson · GitHub
Skip to content

Fix ByteBuf leak in BaseTransactionalMap.isEqual() - #7303

Merged
mrniko merged 1 commit into
redisson:masterfrom
kalayciburak:fix/transactional-map-bytebuf-leak
Aug 17, 2026
Merged

mrniko merged 1 commit into
redisson:masterfrom
kalayciburak:fix/transactional-map-bytebuf-leak

Conversation

@kalayciburak

Copy link
Copy Markdown
Contributor

Problem

BaseTransactionalMap.isEqual() encodes both arguments into ByteBuf objects, but its finally block calls readableBytes() on them instead of release():

private boolean isEqual(Object value, Object oldValue) {
    ByteBuf valueBuf = ((RedissonObject) map).encodeMapValue(value);
    ByteBuf oldValueBuf = ((RedissonObject) map).encodeMapValue(oldValue);
    try {
        return valueBuf.equals(oldValueBuf);
    } finally {
        valueBuf.readableBytes();
        oldValueBuf.readableBytes();
    }
}

readableBytes() only queries the buffer; it does not free it. So both encoded buffers leak on every isEqual() call. The sibling RedissonTransactionalBucket.isEquals() was already fixed in #7216, and BaseTransactionalSet.isEqual() already calls release().

Fix

Release both buffers in the finally block.

Test

Adds RedissonTransactionalMapTest#testContainsValueReleasesEncodedBuffers. It tracks ByteBuf instances allocated by a custom map-value encoder during transactional containsValue() (the path that calls isEqual() on local state) and asserts both buffers are released.

Executed:

  • mvn -pl redisson -Punit-test -Dtest=RedissonTransactionalMapTest#testContainsValueReleasesEncodedBuffers test RED on master (refCnt 1), GREEN after the fix
  • mvn -pl redisson -Punit-test -Dtest=RedissonTransactionalMapTest test 16/16
  • mvn -pl redisson -Punit-test -Dtest=RedissonTransactionalMapCacheTest,RedissonTransactionalSetTest test 25/25

Fixes #7302

isEqual() encoded both values for comparison but called
readableBytes() in the finally block instead of release().
This matches the sibling fix in RedissonTransactionalBucket.

Fixes redisson#7302

Signed-off-by: Burak KALAYCI <kalayciburak1996@gmail.com>
@mrniko mrniko added this to the 4.8.0 milestone Aug 17, 2026
@mrniko mrniko added the bug label Aug 17, 2026
@mrniko
mrniko merged commit 34337f3 into redisson:master Aug 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

ByteBuf leak in BaseTransactionalMap.isEqual()

2 participants