From 7d81b0beab3de7d66c6200e925bb7ac991772728 Mon Sep 17 00:00:00 2001 From: Xiao Chen Date: Thu, 15 Jun 2017 10:40:59 -0700 Subject: [PATCH] HADOOP-14523. OpensslAesCtrCryptoCodec.finalize() holds excessive amounts of memory. Contributed by Misha Dmitriev. (cherry picked from commit ef8edab930338646551cbe3c7e7cf954e21c0f9a) --- .../hadoop/crypto/OpensslAesCtrCryptoCodec.java | 11 ----------- .../apache/hadoop/crypto/random/OsSecureRandom.java | 5 +++++ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/OpensslAesCtrCryptoCodec.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/OpensslAesCtrCryptoCodec.java index 63c382c16e0..d0a12e9fdb5 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/OpensslAesCtrCryptoCodec.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/OpensslAesCtrCryptoCodec.java @@ -19,7 +19,6 @@ package org.apache.hadoop.crypto; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_SECURE_RANDOM_IMPL_KEY; -import java.io.Closeable; import java.io.IOException; import java.nio.ByteBuffer; import java.security.GeneralSecurityException; @@ -71,16 +70,6 @@ public class OpensslAesCtrCryptoCodec extends AesCtrCryptoCodec { } } - @Override - protected void finalize() throws Throwable { - try { - Closeable r = (Closeable) this.random; - r.close(); - } catch (ClassCastException e) { - } - super.finalize(); - } - @Override public Configuration getConf() { return conf; diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/random/OsSecureRandom.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/random/OsSecureRandom.java index 2010e6d84e5..9428b981751 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/random/OsSecureRandom.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/random/OsSecureRandom.java @@ -116,4 +116,9 @@ public class OsSecureRandom extends Random implements Closeable, Configurable { stream = null; } } + + @Override + protected void finalize() throws Throwable { + close(); + } }