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_r349268188
 
 

 ##########
 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:
   I can remove it if you like but that is basically the contract of a 
`ReadableByteChannel`.

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