vanzin 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_r349255715
 
 

 ##########
 File path: 
common/network-common/src/main/java/org/apache/spark/network/util/ByteArrayReadableChannel.java
 ##########
 @@ -19,44 +19,54 @@
 
 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) {
+  public void feedData(ByteBuf buf) throws ClosedChannelException {
+    if (closed) {
+      throw new ClosedChannelException();
+    }
+    if (data != null) {
+      throw new IllegalStateException("Already holding a ByteBuf");
+    }
     data = buf;
   }
 
   @Override
   public int read(ByteBuffer dst) throws IOException {
+    if (closed) {
 
 Review comment:
   This is ok by itself, but I don't see any code calling `close()` so it's 
basically dead code...

----------------------------------------------------------------
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