Commit 1990574e authored by Brian Carlstrom's avatar Brian Carlstrom
Browse files

Scrub missing calls to super.finalize()

Bug: 3024226
Change-Id: I6642cb9d4929ba72244529efe4ebdfa595ae4fa7
parent bee82fd7
......@@ -285,8 +285,12 @@ abstract class AbstractSessionContext implements SSLSessionContext {
"Error converting session.", t);
}
protected void finalize() throws IOException {
NativeCrypto.SSL_CTX_free(sslCtxNativePointer);
@Override protected void finalize() throws Throwable {
try {
NativeCrypto.SSL_CTX_free(sslCtxNativePointer);
} finally {
super.finalize();
}
}
/**
......
......@@ -94,11 +94,13 @@ public class OpenSSLMessageDigestJDK extends MessageDigest implements Cloneable
return d;
}
@Override
protected void finalize() throws Throwable {
super.finalize();
NativeCrypto.EVP_MD_CTX_destroy(ctx);
ctx = 0;
@Override protected void finalize() throws Throwable {
try {
NativeCrypto.EVP_MD_CTX_destroy(ctx);
ctx = 0;
} finally {
super.finalize();
}
}
public static class MD5 extends OpenSSLMessageDigestJDK {
......
......@@ -499,7 +499,11 @@ public class OpenSSLSessionImpl implements SSLSession {
}
}
protected void finalize() {
NativeCrypto.SSL_SESSION_free(sslSessionNativePointer);
@Override protected void finalize() throws Throwable {
try {
NativeCrypto.SSL_SESSION_free(sslSessionNativePointer);
} finally {
super.finalize();
}
}
}
......@@ -232,20 +232,21 @@ public class OpenSSLSignature extends Signature {
}
@Override
protected void finalize() throws Throwable {
super.finalize();
if (dsa != 0) {
NativeCrypto.EVP_PKEY_free(dsa);
}
@Override protected void finalize() throws Throwable {
try {
if (dsa != 0) {
NativeCrypto.EVP_PKEY_free(dsa);
}
if (rsa != 0) {
NativeCrypto.EVP_PKEY_free(rsa);
}
if (rsa != 0) {
NativeCrypto.EVP_PKEY_free(rsa);
}
if (ctx != 0) {
NativeCrypto.EVP_MD_CTX_destroy(ctx);
if (ctx != 0) {
NativeCrypto.EVP_MD_CTX_destroy(ctx);
}
} finally {
super.finalize();
}
}
......
......@@ -1253,25 +1253,28 @@ public class OpenSSLSocketImpl
sslNativePointer = 0;
}
@Override
protected void finalize() throws IOException {
/*
* Just worry about our own state. Notably we do not try and
* close anything. The SocketImpl, either our own
* PlainSocketImpl, or the Socket we are wrapping, will do
* that. This might mean we do not properly SSL_shutdown, but
* if you want to do that, properly close the socket yourself.
*
* The reason why we don't try to SSL_shutdown, is that there
* can be a race between finalizers where the PlainSocketImpl
* finalizer runs first and closes the socket. However, in the
* meanwhile, the underlying file descriptor could be reused
* for another purpose. If we call SSL_shutdown, the
* underlying socket BIOs still have the old file descriptor
* and will write the close notify to some unsuspecting
* reader.
*/
updateInstanceCount(-1);
free();
@Override protected void finalize() throws Throwable {
try {
/*
* Just worry about our own state. Notably we do not try and
* close anything. The SocketImpl, either our own
* PlainSocketImpl, or the Socket we are wrapping, will do
* that. This might mean we do not properly SSL_shutdown, but
* if you want to do that, properly close the socket yourself.
*
* The reason why we don't try to SSL_shutdown, is that there
* can be a race between finalizers where the PlainSocketImpl
* finalizer runs first and closes the socket. However, in the
* meanwhile, the underlying file descriptor could be reused
* for another purpose. If we call SSL_shutdown, the
* underlying socket BIOs still have the old file descriptor
* and will write the close notify to some unsuspecting
* reader.
*/
updateInstanceCount(-1);
free();
} finally {
super.finalize();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment