From 2e0dd65250be7d04f2429cecbc8de31c2e30cb9c Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 1 May 2013 11:14:21 +0900 Subject: [PATCH] Fix a bug where the unpooled buffer returned by the pooled allocator reports an incorrect allocator --- .../java/io/netty/buffer/PooledByteBufAllocator.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java b/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java index 34766c3404..9f614e8e3e 100644 --- a/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java +++ b/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java @@ -82,7 +82,6 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator { private final PoolArena[] heapArenas; private final PoolArena[] directArenas; - private final UnpooledByteBufAllocator unpooledAllocator; final ThreadLocal threadCache = new ThreadLocal() { private final AtomicInteger index = new AtomicInteger(); @@ -151,8 +150,6 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator { } else { directArenas = null; } - - unpooledAllocator = new UnpooledByteBufAllocator(preferDirect); } @SuppressWarnings("unchecked") @@ -208,7 +205,7 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator { if (heapArena != null) { return heapArena.allocate(cache, initialCapacity, maxCapacity); } else { - return unpooledAllocator.newDirectBuffer(initialCapacity, maxCapacity); + return new UnpooledHeapByteBuf(this, initialCapacity, maxCapacity); } } @@ -219,7 +216,11 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator { if (directArena != null) { return directArena.allocate(cache, initialCapacity, maxCapacity); } else { - return unpooledAllocator.newDirectBuffer(initialCapacity, maxCapacity); + if (PlatformDependent.hasUnsafe()) { + return new UnpooledUnsafeDirectByteBuf(this, initialCapacity, maxCapacity); + } else { + return new UnpooledDirectByteBuf(this, initialCapacity, maxCapacity); + } } }