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 committed by GitHub
parent 37267f95ce
commit 44f85bba5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<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;