From 0ad99310f5c02363f9402872d9b3d803654a794d Mon Sep 17 00:00:00 2001 From: louxiu Date: Sun, 16 Jul 2017 15:38:16 +0800 Subject: [PATCH] Record release when enable detailed leak detection Motivation: It would be easier to find where is missing release call in several retain release calls on a ByteBuf Modifications: Remove final modifier on SimpleLeakAwareByteBuf and SimpleLeakAwareByteBuf release function and override it to record release in AdvancedLeakAwareByteBuf and AdvancedLeakAwareCompositeByteBuf Result: Release will be recorded when enable detailed leak detection --- .../io/netty/buffer/AdvancedLeakAwareByteBuf.java | 12 ++++++++++++ .../buffer/AdvancedLeakAwareCompositeByteBuf.java | 12 ++++++++++++ .../java/io/netty/buffer/SimpleLeakAwareByteBuf.java | 4 ++-- .../buffer/SimpleLeakAwareCompositeByteBuf.java | 4 ++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/AdvancedLeakAwareByteBuf.java b/buffer/src/main/java/io/netty/buffer/AdvancedLeakAwareByteBuf.java index 3b08f85120..5fb13c214e 100644 --- a/buffer/src/main/java/io/netty/buffer/AdvancedLeakAwareByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/AdvancedLeakAwareByteBuf.java @@ -931,6 +931,18 @@ final class AdvancedLeakAwareByteBuf extends SimpleLeakAwareByteBuf { return super.retain(increment); } + @Override + public boolean release() { + leak.record(); + return super.release(); + } + + @Override + public boolean release(int decrement) { + leak.record(); + return super.release(decrement); + } + @Override public ByteBuf touch() { leak.record(); diff --git a/buffer/src/main/java/io/netty/buffer/AdvancedLeakAwareCompositeByteBuf.java b/buffer/src/main/java/io/netty/buffer/AdvancedLeakAwareCompositeByteBuf.java index 1c9155fcbd..ff93de665c 100644 --- a/buffer/src/main/java/io/netty/buffer/AdvancedLeakAwareCompositeByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/AdvancedLeakAwareCompositeByteBuf.java @@ -1017,6 +1017,18 @@ final class AdvancedLeakAwareCompositeByteBuf extends SimpleLeakAwareCompositeBy return super.retain(increment); } + @Override + public boolean release() { + leak.record(); + return super.release(); + } + + @Override + public boolean release(int decrement) { + leak.record(); + return super.release(decrement); + } + @Override public CompositeByteBuf touch() { leak.record(); diff --git a/buffer/src/main/java/io/netty/buffer/SimpleLeakAwareByteBuf.java b/buffer/src/main/java/io/netty/buffer/SimpleLeakAwareByteBuf.java index 1a8b0bd56c..e07171258a 100644 --- a/buffer/src/main/java/io/netty/buffer/SimpleLeakAwareByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/SimpleLeakAwareByteBuf.java @@ -98,7 +98,7 @@ class SimpleLeakAwareByteBuf extends WrappedByteBuf { } @Override - public final boolean release() { + public boolean release() { if (super.release()) { closeLeak(); return true; @@ -107,7 +107,7 @@ class SimpleLeakAwareByteBuf extends WrappedByteBuf { } @Override - public final boolean release(int decrement) { + public boolean release(int decrement) { if (super.release(decrement)) { closeLeak(); return true; diff --git a/buffer/src/main/java/io/netty/buffer/SimpleLeakAwareCompositeByteBuf.java b/buffer/src/main/java/io/netty/buffer/SimpleLeakAwareCompositeByteBuf.java index fda06fdf8a..d96f35c0c5 100644 --- a/buffer/src/main/java/io/netty/buffer/SimpleLeakAwareCompositeByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/SimpleLeakAwareCompositeByteBuf.java @@ -31,7 +31,7 @@ class SimpleLeakAwareCompositeByteBuf extends WrappedCompositeByteBuf { } @Override - public final boolean release() { + public boolean release() { // Call unwrap() before just in case that super.release() will change the ByteBuf instance that is returned // by unwrap(). ByteBuf unwrapped = unwrap(); @@ -43,7 +43,7 @@ class SimpleLeakAwareCompositeByteBuf extends WrappedCompositeByteBuf { } @Override - public final boolean release(int decrement) { + public boolean release(int decrement) { // Call unwrap() before just in case that super.release() will change the ByteBuf instance that is returned // by unwrap(). ByteBuf unwrapped = unwrap();