@@ -0,0 +1,1877 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.apache.tomcat.jni;%0A%0Aimport org.junit.Test;%0A%0A/*%0A * Helper class to investigate native memory leaks. Needs to be used with tools%0A * to monitor native memory usage.%0A *%0A * Note: Moving the Pool, SSLContext, SSL and BIO creation in/out of the loop%0A *       can help identify where the memory is leaking.%0A */%0Apublic class TesterSSL %7B%0A%0A    @Test%0A    public void testCreateDestroy() throws Exception %7B%0A        Library.initialize(null);%0A        SSL.initialize(null);%0A%0A        long memoryPool = Pool.create(0);%0A        long sslCtx = SSLContext.make(memoryPool, SSL.SSL_PROTOCOL_ALL, SSL.SSL_MODE_SERVER);%0A%0A        for (int i = 0; i %3C 10000000; i++) %7B%0A            doNative(sslCtx);%0A            if (i %25 1000 == 0) %7B%0A                System.gc();%0A            %7D%0A        %7D%0A%0A        SSLContext.free(sslCtx);%0A        Pool.destroy(memoryPool);%0A%0A        System.gc();%0A    %7D%0A%0A%0A    private void doNative(long sslCtx) throws Exception %7B%0A        long ssl = SSL.newSSL(sslCtx, true);%0A        long bio = SSL.makeNetworkBIO(ssl);%0A        SSL.freeBIO(bio);%0A        SSL.freeSSL(ssl);%0A    %7D%0A%7D%0A

Add helper class I used to track down NIO[2]+OpenSSL memory leak in Tomcat Native.