GeezerVison is showing github.com — Remove reference to parent in recycled buffers for leak detection (#1… · netty/netty@fe932ff
File tree
Expand file treeCollapse file tree
Open diff view settings
buffer/src/main/java/io/netty/buffer
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: buffer/src/main/java/io/netty/buffer/AbstractPooledDerivedByteBuf.java +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
16 | 16 |
|
17 | 17 | package io.netty.buffer; |
18 | 18 |
|
| 19 | +import io.netty.util.IllegalReferenceCountException; |
19 | 20 | import io.netty.util.Recycler.EnhancedHandle; |
20 | 21 | import io.netty.util.internal.ObjectPool.Handle; |
21 | 22 |
|
@@ -51,6 +52,10 @@ final void parent(ByteBuf newParent) { |
51 | 52 |
|
52 | 53 | @Override |
53 | 54 | public final AbstractByteBuf unwrap() { |
| 55 | + AbstractByteBuf rootParent = this.rootParent; |
| 56 | + if (rootParent == null) { |
| 57 | + throw new IllegalReferenceCountException(); |
| 58 | + } |
54 | 59 | return rootParent; |
55 | 60 | } |
56 | 61 |
|
@@ -83,6 +88,8 @@ protected final void deallocate() { |
83 | 88 | // otherwise it is possible that the same AbstractPooledDerivedByteBuf is again obtained and init(...) is |
84 | 89 | // called before we actually have a chance to call release(). This leads to call release() on the wrong parent. |
85 | 90 | ByteBuf parent = this.parent; |
| 91 | + // Remove references to parent and root so that they can be GCed for leak detection [netty/netty#14247] |
| 92 | + this.parent = this.rootParent = null; |
86 | 93 | recyclerHandle.unguardedRecycle(this); |
87 | 94 | parent.release(); |
88 | 95 | } |
|