[#5190] Ensure memory is not leaked when readEndOfLine(...) throws an exception.
Motivation: We need to ensure we not retain the buffer until readEndOfLine(...) completes as otherwise we may leak memory in the case of an exception. Modifications: Only call retain after readEndOfLine(...) returns. Result: No more leak in case of exception while decoding redis messages.
This commit is contained in:
parent
ef13d19b8b
commit
06436efaa1
@ -205,9 +205,10 @@ public final class RedisDecoder extends ByteToMessageDecoder {
|
||||
|
||||
// if this is last frame.
|
||||
if (readableBytes >= remainingBulkLength + RedisConstants.EOL_LENGTH) {
|
||||
ByteBuf content = in.readSlice(remainingBulkLength).retain();
|
||||
ByteBuf content = in.readSlice(remainingBulkLength);
|
||||
readEndOfLine(in);
|
||||
out.add(new DefaultLastBulkStringRedisContent(content));
|
||||
// Only call retain after readEndOfLine(...) as the method may throw an exception.
|
||||
out.add(new DefaultLastBulkStringRedisContent(content.retain()));
|
||||
resetDecoder();
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user