[#1297] Make sure ResourceLeakDetector.open(...) is only used after constructing was successful
This commit is contained in:
parent
f979c17b67
commit
9a5f45a0c1
@ -45,7 +45,7 @@ public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf
|
||||
|
||||
private static final ByteBuffer[] EMPTY_NIOBUFFERS = new ByteBuffer[0];
|
||||
|
||||
private final ResourceLeak leak = leakDetector.open(this);
|
||||
private final ResourceLeak leak;
|
||||
private final ByteBufAllocator alloc;
|
||||
private final boolean direct;
|
||||
private final List<Component> components = new ArrayList<Component>();
|
||||
@ -64,6 +64,7 @@ public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf
|
||||
this.alloc = alloc;
|
||||
this.direct = direct;
|
||||
this.maxNumComponents = maxNumComponents;
|
||||
leak = leakDetector.open(this);
|
||||
}
|
||||
|
||||
public DefaultCompositeByteBuf(ByteBufAllocator alloc, boolean direct, int maxNumComponents, ByteBuf... buffers) {
|
||||
@ -83,6 +84,7 @@ public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf
|
||||
addComponents0(0, buffers);
|
||||
consolidateIfNeeded();
|
||||
setIndex(0, capacity());
|
||||
leak = leakDetector.open(this);
|
||||
}
|
||||
|
||||
public DefaultCompositeByteBuf(
|
||||
@ -102,6 +104,7 @@ public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf
|
||||
addComponents0(0, buffers);
|
||||
consolidateIfNeeded();
|
||||
setIndex(0, capacity());
|
||||
leak = leakDetector.open(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,7 @@ import java.util.Queue;
|
||||
|
||||
abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
|
||||
|
||||
private final ResourceLeak leak = leakDetector.open(this);
|
||||
private final ResourceLeak leak;
|
||||
|
||||
protected PoolChunk<T> chunk;
|
||||
protected long handle;
|
||||
@ -39,6 +39,7 @@ abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
|
||||
|
||||
protected PooledByteBuf(int maxCapacity) {
|
||||
super(maxCapacity);
|
||||
leak = leakDetector.open(this);
|
||||
}
|
||||
|
||||
void init(PoolChunk<T> chunk, long handle, int offset, int length, int maxLength) {
|
||||
|
@ -31,7 +31,7 @@ import java.nio.channels.ScatteringByteChannel;
|
||||
* Read-only ByteBuf which wraps a read-only ByteBuffer.
|
||||
*/
|
||||
class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf {
|
||||
private final ResourceLeak leak = leakDetector.open(this);
|
||||
private final ResourceLeak leak;
|
||||
|
||||
protected final ByteBuffer buffer;
|
||||
private final ByteBufAllocator allocator;
|
||||
@ -46,6 +46,7 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf {
|
||||
this.allocator = allocator;
|
||||
this.buffer = buffer.slice().order(ByteOrder.BIG_ENDIAN);
|
||||
writerIndex(buffer.limit());
|
||||
leak = leakDetector.open(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,7 +36,7 @@ import java.util.Queue;
|
||||
*/
|
||||
public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
|
||||
|
||||
private final ResourceLeak leak = leakDetector.open(this);
|
||||
private final ResourceLeak leak;
|
||||
private final ByteBufAllocator alloc;
|
||||
|
||||
private ByteBuffer buffer;
|
||||
@ -69,6 +69,7 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
|
||||
|
||||
this.alloc = alloc;
|
||||
setByteBuffer(ByteBuffer.allocateDirect(initialCapacity));
|
||||
leak = leakDetector.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,6 +102,7 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
|
||||
doNotFree = true;
|
||||
setByteBuffer(initialBuffer.slice().order(ByteOrder.BIG_ENDIAN));
|
||||
writerIndex(initialCapacity);
|
||||
leak = leakDetector.open(this);
|
||||
}
|
||||
|
||||
private void setByteBuffer(ByteBuffer buffer) {
|
||||
|
@ -38,7 +38,7 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
|
||||
|
||||
private static final boolean NATIVE_ORDER = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
|
||||
|
||||
private final ResourceLeak leak = leakDetector.open(this);
|
||||
private final ResourceLeak leak;
|
||||
private final ByteBufAllocator alloc;
|
||||
|
||||
private long memoryAddress;
|
||||
@ -72,6 +72,7 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
|
||||
|
||||
this.alloc = alloc;
|
||||
setByteBuffer(ByteBuffer.allocateDirect(initialCapacity));
|
||||
leak = leakDetector.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,6 +105,7 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
|
||||
doNotFree = true;
|
||||
setByteBuffer(initialBuffer.slice().order(ByteOrder.BIG_ENDIAN));
|
||||
writerIndex(initialCapacity);
|
||||
leak = leakDetector.open(this);
|
||||
}
|
||||
|
||||
private void setByteBuffer(ByteBuffer buffer) {
|
||||
|
@ -82,7 +82,7 @@ public class HashedWheelTimer implements Timer {
|
||||
new ResourceLeakDetector<HashedWheelTimer>(
|
||||
HashedWheelTimer.class, 1, Runtime.getRuntime().availableProcessors() * 4);
|
||||
|
||||
private final ResourceLeak leak = leakDetector.open(this);
|
||||
private final ResourceLeak leak;
|
||||
private final Worker worker = new Worker();
|
||||
final Thread workerThread;
|
||||
|
||||
@ -207,6 +207,7 @@ public class HashedWheelTimer implements Timer {
|
||||
}
|
||||
|
||||
workerThread = threadFactory.newThread(worker);
|
||||
leak = leakDetector.open(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
Loading…
Reference in New Issue
Block a user