From a06c6f89169d339c98da57c1d308d79013a46c83 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/io/netty/util/ResourceLeakDetector.java b/common/src/main/java/io/netty/util/ResourceLeakDetector.java index ff3981436a..e6d52e12fb 100644 --- a/common/src/main/java/io/netty/util/ResourceLeakDetector.java +++ b/common/src/main/java/io/netty/util/ResourceLeakDetector.java @@ -570,10 +570,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;