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
This commit is contained in:
Norman Maurer 2020-12-05 07:01:03 +01:00
parent 19c121ab8d
commit a06c6f8916

View File

@ -570,10 +570,20 @@ public class ResourceLeakDetector<T> {
} 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;