From 44f85bba5f47df885dbbe5243d008220bfbab5ca Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sat, 5 Dec 2020 07:01:03 +0100 Subject: [PATCH] Ensure we don't leak the ClassLoader in the backtrace of TrackRecord.BOTTOM (#10839) Motivation: We need to ensure we override fillInStacktrace() when we store exceptions in static fields to not leak the Classloader in the backtrace. Came up in https://github.com/netty/netty/pull/10691#issuecomment-738331186. Thanks to @amir-shalem for notice this one. Modifications: - Add overrides of fillInStracktrace in TrackRecord.BOTTOM Result: Related fix to https://github.com/netty/netty/pull/10686 --- .../java/io/netty/util/ResourceLeakDetector.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/io/netty/util/ResourceLeakDetector.java b/common/src/main/java/io/netty/util/ResourceLeakDetector.java index 3e1c17b26e..be6845683d 100644 --- a/common/src/main/java/io/netty/util/ResourceLeakDetector.java +++ b/common/src/main/java/io/netty/util/ResourceLeakDetector.java @@ -31,7 +31,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; @@ -588,10 +587,20 @@ public class ResourceLeakDetector { } while (!excludedMethods.compareAndSet(oldMethods, newMethods)); } - private static final class TraceRecord extends Throwable { + private static class TraceRecord extends Throwable { private static final long serialVersionUID = 6065153674892850720L; - private static final TraceRecord BOTTOM = new TraceRecord(); + private static final TraceRecord BOTTOM = new TraceRecord() { + private static final long serialVersionUID = 7396077602074694571L; + + // Override fillInStackTrace() so we not populate the backtrace via a native call and so leak the + // Classloader. + // See https://github.com/netty/netty/pull/10691 + @Override + public Throwable fillInStackTrace() { + return this; + } + }; private final String hintString; private final TraceRecord next;