From 7231be592aa65ac1e91d0a319761f7e3df2225e9 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 12 Nov 2013 12:40:41 +0100 Subject: [PATCH] Also allow to override how direct ByteBuffers are freed --- .../java/io/netty/buffer/UnpooledDirectByteBuf.java | 11 +++++++++-- .../io/netty/buffer/UnpooledUnsafeDirectByteBuf.java | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/UnpooledDirectByteBuf.java b/buffer/src/main/java/io/netty/buffer/UnpooledDirectByteBuf.java index 897c8f33ff..a61d3c5eac 100644 --- a/buffer/src/main/java/io/netty/buffer/UnpooledDirectByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/UnpooledDirectByteBuf.java @@ -109,13 +109,20 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf { return ByteBuffer.allocateDirect(initialCapacity); } + /** + * Free a direct {@link ByteBuffer} + */ + protected void freeDirect(ByteBuffer buffer) { + PlatformDependent.freeDirectBuffer(buffer); + } + private void setByteBuffer(ByteBuffer buffer) { ByteBuffer oldBuffer = this.buffer; if (oldBuffer != null) { if (doNotFree) { doNotFree = false; } else { - PlatformDependent.freeDirectBuffer(oldBuffer); + freeDirect(oldBuffer); } } @@ -595,7 +602,7 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf { this.buffer = null; if (!doNotFree) { - PlatformDependent.freeDirectBuffer(buffer); + freeDirect(buffer); } if (leak != null) { diff --git a/buffer/src/main/java/io/netty/buffer/UnpooledUnsafeDirectByteBuf.java b/buffer/src/main/java/io/netty/buffer/UnpooledUnsafeDirectByteBuf.java index f859217c2c..50fdf02aee 100644 --- a/buffer/src/main/java/io/netty/buffer/UnpooledUnsafeDirectByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/UnpooledUnsafeDirectByteBuf.java @@ -112,13 +112,20 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf return ByteBuffer.allocateDirect(initialCapacity); } + /** + * Free a direct {@link ByteBuffer} + */ + protected void freeDirect(ByteBuffer buffer) { + PlatformDependent.freeDirectBuffer(buffer); + } + private void setByteBuffer(ByteBuffer buffer) { ByteBuffer oldBuffer = this.buffer; if (oldBuffer != null) { if (doNotFree) { doNotFree = false; } else { - PlatformDependent.freeDirectBuffer(oldBuffer); + freeDirect(oldBuffer); } } @@ -495,7 +502,7 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf this.buffer = null; if (!doNotFree) { - PlatformDependent.freeDirectBuffer(buffer); + freeDirect(buffer); } if (leak != null) {