From 46ed4fd7feef1f440c10151f7036d26ccdfc71ea Mon Sep 17 00:00:00 2001 From: Le Thanh Date: Tue, 5 Nov 2024 09:54:54 +0700 Subject: [PATCH] Fix potential memory leak on method LocalCacheView.toCacheKey if useObjectAsCacheKey = true Signed-off-by: Le Thanh --- .../java/org/redisson/RedissonLocalCachedMap.java | 1 + .../main/java/org/redisson/cache/LocalCacheView.java | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java index 9c5859dd6..f51be2f6c 100644 --- a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java +++ b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java @@ -150,6 +150,7 @@ public class RedissonLocalCachedMap extends RedissonMap implements R } listener.notifyInvalidate(new CacheValue(key, oldV)); listener.notifyUpdate(newValue); + localCacheView.putCacheKey(key, cacheKey); return oldValue; } diff --git a/redisson/src/main/java/org/redisson/cache/LocalCacheView.java b/redisson/src/main/java/org/redisson/cache/LocalCacheView.java index 10d412d56..c6ea759d8 100644 --- a/redisson/src/main/java/org/redisson/cache/LocalCacheView.java +++ b/redisson/src/main/java/org/redisson/cache/LocalCacheView.java @@ -281,16 +281,18 @@ public class LocalCacheView { } ByteBuf encoded = object.encodeMapKey(key); try { - cacheKey = toCacheKey(encoded); - if (useObjectAsCacheKey) { - cacheKeyMap.put(key, cacheKey); - } - return cacheKey; + return toCacheKey(encoded); } finally { encoded.release(); } } + public void putCacheKey(Object key, CacheKey cacheKey) { + if (useObjectAsCacheKey) { + cacheKeyMap.put(key, cacheKey); + } + } + public CacheKey toCacheKey(ByteBuf encodedKey) { return new CacheKey(Hash.hash128toArray(encodedKey)); }