You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/07/21 05:58:00 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #19410: Fix MySQLJsonBinlogProtocolValue may cause leak

sandynz commented on code in PR #19410:
URL: https://github.com/apache/shardingsphere/pull/19410#discussion_r926280616


##########
shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLJsonBinlogProtocolValue.java:
##########
@@ -39,7 +40,10 @@ public final class MySQLJsonBinlogProtocolValue implements MySQLBinlogProtocolVa
     
     @Override
     public Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload) {
-        return MySQLJsonValueDecoder.decode(payload.getByteBuf().readBytes(readLengthFromMeta(columnDef.getColumnMeta(), payload)));
+        ByteBuf newByteBuf = payload.getByteBuf().readBytes(readLengthFromMeta(columnDef.getColumnMeta(), payload));
+        Serializable result = MySQLJsonValueDecoder.decode(newByteBuf);
+        newByteBuf.release();
+        return result;

Review Comment:
   It's better to do release() in finally block if we keep allocating a new ByteBuf, since MySQLJsonValueDecoder.decode might throw exception.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org