Fix a bug in internalNioBuffer() implementations of derived buffers

- A user can create multiple duplicates of a buffer and access their internal NIO buffers. (e.g. write multiple duplicates to multiple channels assigned to different event loop.)  Because the derived buffers' internalNioBuffer() simply delegates the call to the original buffer, all derived buffers and the original buffer's internalNioBuffer() will return the same buffer, which will lead to a race condition.
- Fixes #1739
This commit is contained in:
Trustin Lee 2013-08-20 14:28:50 +09:00
parent a383988cdb
commit 20894bc99e
4 changed files with 4 additions and 5 deletions

View File

@ -289,7 +289,7 @@ public class DuplicatedByteBuf extends AbstractDerivedByteBuf {
@Override @Override
public ByteBuffer internalNioBuffer(int index, int length) { public ByteBuffer internalNioBuffer(int index, int length) {
return buffer.internalNioBuffer(index, length); return buffer.internalNioBuffer(index, length).duplicate();
} }
@Override @Override

View File

@ -292,7 +292,7 @@ public class ReadOnlyByteBuf extends AbstractDerivedByteBuf {
@Override @Override
public ByteBuffer internalNioBuffer(int index, int length) { public ByteBuffer internalNioBuffer(int index, int length) {
return buffer.internalNioBuffer(index, length); return buffer.internalNioBuffer(index, length).duplicate();
} }
@Override @Override

View File

@ -271,7 +271,7 @@ public class SlicedByteBuf extends AbstractDerivedByteBuf {
@Override @Override
public ByteBuffer internalNioBuffer(int index, int length) { public ByteBuffer internalNioBuffer(int index, int length) {
checkIndex(index, length); checkIndex(index, length);
return buffer.internalNioBuffer(index + adjustment, length); return buffer.internalNioBuffer(index + adjustment, length).duplicate();
} }
@Override @Override

View File

@ -741,8 +741,7 @@ public final class SwappedByteBuf extends ByteBuf {
@Override @Override
public ByteBuffer internalNioBuffer(int index, int length) { public ByteBuffer internalNioBuffer(int index, int length) {
// Do not mess with the internal buffer's byte order. return buf.internalNioBuffer(index, length).duplicate().order(order);
return buf.nioBuffer(index, length).order(order);
} }
@Override @Override