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