diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpData.java b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpData.java index b6aa0ccdf4..4e21627c02 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpData.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpData.java @@ -53,6 +53,9 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData { throw new IOException("Out of size: " + localsize + " > " + definedSize); } + if (byteBuf != null) { + byteBuf.release(); + } byteBuf = buffer; size = localsize; completed = true; @@ -76,6 +79,9 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData { if (definedSize > 0 && definedSize < size) { throw new IOException("Out of size: " + size + " > " + definedSize); } + if (byteBuf != null) { + byteBuf.release(); + } byteBuf = buffer; completed = true; } @@ -133,6 +139,9 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData { fileChannel.close(); inputStream.close(); byteBuffer.flip(); + if (byteBuf != null) { + byteBuf.release(); + } byteBuf = wrappedBuffer(byteBuffer); size = newsize; completed = true;