From cda657839ba9399aaaea065c75706463095cd3ab Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Wed, 29 Sep 2021 13:54:13 -0600 Subject: [PATCH] free native WOLFSSL when WolfSSLSocket is closed, earlier than finalize --- src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java b/src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java index 916b680..06f8d25 100644 --- a/src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java +++ b/src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java @@ -1371,6 +1371,12 @@ public class WolfSSLSocket extends SSLSocket { synchronized (handshakeLock) { this.connectionClosed = true; + + /* Connection is closed, free native WOLFSSL session + * to release native memory earlier than garbage collector + * might with finalize(). */ + this.ssl.freeSSL(); + this.ssl = null; } } @@ -1396,6 +1402,8 @@ public class WolfSSLSocket extends SSLSocket { } catch (IllegalStateException e) { throw new IOException(e); + } catch (WolfSSLJNIException jnie) { + throw new IOException(jnie); } }