wrap WolfSSLContext finalizer free to catch IllegalStateException if already freed
parent
427c8782da
commit
ccd0456a08
|
@ -40,7 +40,7 @@ import com.wolfssl.WolfSSLJNIException;
|
||||||
public class WolfSSLContext {
|
public class WolfSSLContext {
|
||||||
|
|
||||||
/* internal native WOLFSSL_CTX pointer */
|
/* internal native WOLFSSL_CTX pointer */
|
||||||
private long sslCtxPtr;
|
private long sslCtxPtr = 0;
|
||||||
|
|
||||||
/* user-registerd I/O callbacks, called by internal WolfSSLContext
|
/* user-registerd I/O callbacks, called by internal WolfSSLContext
|
||||||
* I/O callback. This is done in order to pass references to
|
* I/O callback. This is done in order to pass references to
|
||||||
|
@ -100,6 +100,9 @@ public class WolfSSLContext {
|
||||||
|
|
||||||
long getContextPtr()
|
long getContextPtr()
|
||||||
{
|
{
|
||||||
|
if (this.active == false) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return sslCtxPtr;
|
return sslCtxPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,10 +569,11 @@ public class WolfSSLContext {
|
||||||
throw new IllegalStateException("Object has been freed");
|
throw new IllegalStateException("Object has been freed");
|
||||||
|
|
||||||
/* free native resources */
|
/* free native resources */
|
||||||
freeContext(getContextPtr());
|
freeContext(this.sslCtxPtr);
|
||||||
|
|
||||||
/* free Java resources */
|
/* free Java resources */
|
||||||
this.active = false;
|
this.active = false;
|
||||||
|
this.sslCtxPtr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1695,8 +1699,11 @@ public class WolfSSLContext {
|
||||||
protected void finalize() throws Throwable
|
protected void finalize() throws Throwable
|
||||||
{
|
{
|
||||||
if (this.active == true) {
|
if (this.active == true) {
|
||||||
/* free resources, set state */
|
try {
|
||||||
this.free();
|
this.free();
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
/* already freed */
|
||||||
|
}
|
||||||
this.active = false;
|
this.active = false;
|
||||||
}
|
}
|
||||||
super.finalize();
|
super.finalize();
|
||||||
|
|
Loading…
Reference in New Issue