Fix buffer leak in EpollDatagramChannel
Motivation: EpollDatagramChannel produced buffer leaks when tried to read from the channel and nothing was ready to be read. Modifications: Correctly release buffer if nothing was read Result: No buffer leak
This commit is contained in:
parent
97553069b6
commit
d6ec44c871
@ -376,12 +376,11 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
|
|||||||
|
|
||||||
assert eventLoop().inEventLoop();
|
assert eventLoop().inEventLoop();
|
||||||
final ChannelPipeline pipeline = pipeline();
|
final ChannelPipeline pipeline = pipeline();
|
||||||
Throwable exception = null;
|
|
||||||
try {
|
|
||||||
try {
|
try {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
boolean free = true;
|
ByteBuf data = null;
|
||||||
ByteBuf data = allocHandle.allocate(config.getAllocator());
|
try {
|
||||||
|
data = allocHandle.allocate(config.getAllocator());
|
||||||
int writerIndex = data.writerIndex();
|
int writerIndex = data.writerIndex();
|
||||||
DatagramSocketAddress remoteAddress;
|
DatagramSocketAddress remoteAddress;
|
||||||
if (data.hasMemoryAddress()) {
|
if (data.hasMemoryAddress()) {
|
||||||
@ -401,29 +400,20 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
|
|||||||
int readBytes = remoteAddress.receivedAmount;
|
int readBytes = remoteAddress.receivedAmount;
|
||||||
data.writerIndex(data.writerIndex() + readBytes);
|
data.writerIndex(data.writerIndex() + readBytes);
|
||||||
allocHandle.record(readBytes);
|
allocHandle.record(readBytes);
|
||||||
try {
|
|
||||||
readPending = false;
|
readPending = false;
|
||||||
pipeline.fireChannelRead(
|
pipeline.fireChannelRead(
|
||||||
new DatagramPacket(data, (InetSocketAddress) localAddress(), remoteAddress));
|
new DatagramPacket(data, (InetSocketAddress) localAddress(), remoteAddress));
|
||||||
free = false;
|
data = null;
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
// keep on reading as we use epoll ET and need to consume everything from the socket
|
// keep on reading as we use epoll ET and need to consume everything from the socket
|
||||||
pipeline.fireChannelReadComplete();
|
pipeline.fireChannelReadComplete();
|
||||||
pipeline.fireExceptionCaught(t);
|
pipeline.fireExceptionCaught(t);
|
||||||
} finally {
|
} finally {
|
||||||
if (free) {
|
if (data != null) {
|
||||||
data.release();
|
data.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
|
||||||
exception = t;
|
|
||||||
}
|
|
||||||
pipeline.fireChannelReadComplete();
|
|
||||||
|
|
||||||
if (exception != null) {
|
|
||||||
pipeline.fireExceptionCaught(exception);
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
// Check if there is a readPending which was not processed yet.
|
// Check if there is a readPending which was not processed yet.
|
||||||
// This could be for two reasons:
|
// This could be for two reasons:
|
||||||
|
Loading…
Reference in New Issue
Block a user