Fix false-positive leak detection report when ReferenceCountedOpenSslEngine constructor throws.
Motivation: We need to ensure we only create the ResourceLeak when the constructor not throws. Modifications: Ensure ResourceLeakDetector.track(...) is only called if the constructor of ReferenceCoundedOpenSslEngine not throws. Result: No more false-positves.
This commit is contained in:
parent
60250f3795
commit
c5b5d36360
@ -235,7 +235,6 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
|
||||
int peerPort, boolean jdkCompatibilityMode, boolean leakDetection) {
|
||||
super(peerHost, peerPort);
|
||||
OpenSsl.ensureAvailability();
|
||||
leak = leakDetection ? leakDetector.track(this) : null;
|
||||
this.alloc = checkNotNull(alloc, "alloc");
|
||||
apn = (OpenSslApplicationProtocolNegotiator) context.applicationProtocolNegotiator();
|
||||
session = new OpenSslSession(context.sessionContext());
|
||||
@ -288,6 +287,7 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
|
||||
PlatformDependent.throwException(cause);
|
||||
}
|
||||
}
|
||||
leak = leakDetection ? leakDetector.track(this) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,9 @@
|
||||
*/
|
||||
package io.netty.handler.ssl;
|
||||
|
||||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.net.ssl.SSLEngine;
|
||||
|
||||
@ -54,4 +56,14 @@ public class ReferenceCountedOpenSslEngineTest extends OpenSslEngineTest {
|
||||
protected void cleanupServerSslEngine(SSLEngine engine) {
|
||||
ReferenceCountUtil.release(engine);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testNotLeakOnException() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.build();
|
||||
|
||||
clientSslCtx.newEngine(null);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user