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_r349254136
##########
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) {
Review comment:
Where are you setting `data` to null?
(In the spirit of keeping this class as small and dumb as possible, it might
be better to check that `buffer.readableBytes()` is 0 before returning from
`channelRead`. Then you may even be able to get rid of the `readableBytes()`
method in this class.)
----------------------------------------------------------------
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]