normanmaurer commented on a change in pull request #26609: [SPARK-29971] Fix 
multiple possible buffer leaks in `TransportFrameDecoder/TransportCipher`
URL: https://github.com/apache/spark/pull/26609#discussion_r348701930
 
 

 ##########
 File path: 
common/network-common/src/main/java/org/apache/spark/network/util/ByteArrayReadableChannel.java
 ##########
 @@ -19,23 +19,64 @@
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
 import java.nio.channels.ReadableByteChannel;
 
 import io.netty.buffer.ByteBuf;
 
 public class ByteArrayReadableChannel implements ReadableByteChannel {
   private ByteBuf data;
+  private boolean closed;
 
   public int readableBytes() {
-    return data.readableBytes();
+    return data == null ? 0 : data.readableBytes();
   }
 
   public void feedData(ByteBuf buf) {
-    data = buf;
+    if (closed) {
+      buf.release();
+      return;
+    }
+    ByteBuf currentData = data;
+    if (currentData == null) {
+      data = buf;
+    } else {
+      int currentReadable = currentData.readableBytes();
 
 Review comment:
   @vanzin the class is public and as it is today very error-prone. What 
happens if someone start using it from another place ? So either we should 
throw or change the class to be safe to use (which I did here). If you prefer 
throwing that's fine as well.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to