[#1516] Fix resource leakage which was caused by the AbstractDiskHttpData which did not release the buffer after copy to disk
This commit is contained in:
parent
08b75e594c
commit
45d20d5c9f
@ -99,6 +99,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
|||||||
if (buffer == null) {
|
if (buffer == null) {
|
||||||
throw new NullPointerException("buffer");
|
throw new NullPointerException("buffer");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
size = buffer.readableBytes();
|
size = buffer.readableBytes();
|
||||||
if (definedSize > 0 && definedSize < size) {
|
if (definedSize > 0 && definedSize < size) {
|
||||||
throw new IOException("Out of size: " + size + " > " + definedSize);
|
throw new IOException("Out of size: " + size + " > " + definedSize);
|
||||||
@ -123,12 +124,18 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
|||||||
localfileChannel.close();
|
localfileChannel.close();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
completed = true;
|
completed = true;
|
||||||
|
} finally {
|
||||||
|
// Release the buffer as it was retained before and we not need a reference to it at all
|
||||||
|
// See https://github.com/netty/netty/issues/1516
|
||||||
|
buffer.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addContent(ByteBuf buffer, boolean last)
|
public void addContent(ByteBuf buffer, boolean last)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (buffer != null) {
|
if (buffer != null) {
|
||||||
|
try {
|
||||||
int localsize = buffer.readableBytes();
|
int localsize = buffer.readableBytes();
|
||||||
if (definedSize > 0 && definedSize < size + localsize) {
|
if (definedSize > 0 && definedSize < size + localsize) {
|
||||||
throw new IOException("Out of size: " + (size + localsize) +
|
throw new IOException("Out of size: " + (size + localsize) +
|
||||||
@ -148,6 +155,11 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
|||||||
}
|
}
|
||||||
size += localsize;
|
size += localsize;
|
||||||
buffer.readerIndex(buffer.readerIndex() + written);
|
buffer.readerIndex(buffer.readerIndex() + written);
|
||||||
|
} finally {
|
||||||
|
// Release the buffer as it was retained before and we not need a reference to it at all
|
||||||
|
// See https://github.com/netty/netty/issues/1516
|
||||||
|
buffer.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (last) {
|
if (last) {
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user