You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by zh...@apache.org on 2015/02/06 22:47:05 UTC
[33/50] [abbrv] hadoop git commit: HADOOP-11526. Memory leak in
Bzip2Compressor and Bzip2Decompressor. Contributed by Anu Engineer.
HADOOP-11526. Memory leak in Bzip2Compressor and Bzip2Decompressor. Contributed by Anu Engineer.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ee9c025b
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ee9c025b
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ee9c025b
Branch: refs/heads/HDFS-EC
Commit: ee9c025b538d5a53c7a62724e09396a21618535f
Parents: 0f143b2
Author: cnauroth <cn...@apache.org>
Authored: Thu Feb 5 16:53:34 2015 -0800
Committer: Zhe Zhang <zh...@apache.org>
Committed: Fri Feb 6 13:45:51 2015 -0800
----------------------------------------------------------------------
hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++
.../hadoop/io/compress/bzip2/Bzip2Compressor.c | 28 +++++++++++++++-----
.../io/compress/bzip2/Bzip2Decompressor.c | 28 +++++++++++++++-----
3 files changed, 47 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/ee9c025b/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index 8b73d5a..aee3a23 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -864,6 +864,9 @@ Release 2.7.0 - UNRELEASED
HADOOP-11543. Improve help message for hadoop/yarn command.
(Brahma Reddy Battula via ozawa)
+ HADOOP-11526. Memory leak in Bzip2Compressor and Bzip2Decompressor.
+ (Anu Engineer via cnauroth)
+
Release 2.6.1 - UNRELEASED
INCOMPATIBLE CHANGES
http://git-wip-us.apache.org/repos/asf/hadoop/blob/ee9c025b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/bzip2/Bzip2Compressor.c
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/bzip2/Bzip2Compressor.c b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/bzip2/Bzip2Compressor.c
index d4cd6df..ef81bea 100644
--- a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/bzip2/Bzip2Compressor.c
+++ b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/bzip2/Bzip2Compressor.c
@@ -43,15 +43,25 @@ JNIEXPORT void JNICALL
Java_org_apache_hadoop_io_compress_bzip2_Bzip2Compressor_initIDs(
JNIEnv *env, jclass class, jstring libname)
{
- const char* bzlib_name = (*env)->GetStringUTFChars(env, libname, NULL);
- if (strcmp(bzlib_name, "system-native") == 0)
- bzlib_name = HADOOP_BZIP2_LIBRARY;
+ const char *bzlib_name = NULL;
+ const char *java_lib_name = (*env)->GetStringUTFChars(env, libname, NULL);
+ if (java_lib_name == NULL) {
+ // Java code will get OutOfMemoryException thrown by GetStringUTFChars
+ goto cleanup;
+ }
+
+ if (strcmp(java_lib_name, "system-native") == 0) {
+ bzlib_name = HADOOP_BZIP2_LIBRARY;
+ } else {
+ bzlib_name = java_lib_name;
+ }
+
// Load the native library.
void *libbz2 = dlopen(bzlib_name, RTLD_LAZY | RTLD_GLOBAL);
if (!libbz2) {
THROW(env, "java/lang/UnsatisfiedLinkError",
"Cannot load bzip2 native library");
- return;
+ goto cleanup;
}
// Locate the requisite symbols from libbz2.so.
@@ -83,6 +93,11 @@ Java_org_apache_hadoop_io_compress_bzip2_Bzip2Compressor_initIDs(
"Ljava/nio/Buffer;");
Bzip2Compressor_directBufferSize = (*env)->GetFieldID(env, class,
"directBufferSize", "I");
+ cleanup:
+ if(java_lib_name != NULL) {
+ (*env)->ReleaseStringUTFChars(env,libname,java_lib_name);
+ java_lib_name = NULL;
+ }
}
JNIEXPORT jlong JNICALL
@@ -234,9 +249,10 @@ Java_org_apache_hadoop_io_compress_bzip2_Bzip2Compressor_end(
{
if (dlsym_BZ2_bzCompressEnd(BZSTREAM(stream)) != BZ_OK) {
THROW(env, "java/lang/InternalError", NULL);
- } else {
- free(BZSTREAM(stream));
}
+
+ free(BZSTREAM(stream));
+
}
JNIEXPORT jstring JNICALL
http://git-wip-us.apache.org/repos/asf/hadoop/blob/ee9c025b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/bzip2/Bzip2Decompressor.c
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/bzip2/Bzip2Decompressor.c b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/bzip2/Bzip2Decompressor.c
index b6c5213..ad9bcb7 100644
--- a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/bzip2/Bzip2Decompressor.c
+++ b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/bzip2/Bzip2Decompressor.c
@@ -42,15 +42,25 @@ JNIEXPORT void JNICALL
Java_org_apache_hadoop_io_compress_bzip2_Bzip2Decompressor_initIDs(
JNIEnv *env, jclass class, jstring libname)
{
- const char* bzlib_name = (*env)->GetStringUTFChars(env, libname, NULL);
- if (strcmp(bzlib_name, "system-native") == 0)
- bzlib_name = HADOOP_BZIP2_LIBRARY;
+ const char *bzlib_name = NULL;
+ const char *java_lib_name = (*env)->GetStringUTFChars(env, libname, NULL);
+ if (java_lib_name == NULL) {
+ // Java code will get OutOfMemoryException thrown by GetStringUTFChars
+ goto cleanup;
+ }
+
+ if (strcmp(java_lib_name, "system-native") == 0) {
+ bzlib_name = HADOOP_BZIP2_LIBRARY;
+ } else {
+ bzlib_name = java_lib_name;
+ }
+
// Load the native library.
void *libbz2 = dlopen(bzlib_name, RTLD_LAZY | RTLD_GLOBAL);
if (!libbz2) {
THROW(env, "java/lang/UnsatisfiedLinkError",
"Cannot load bzip2 native library");
- return;
+ goto cleanup;
}
// Locate the requisite symbols from libbz2.so.
@@ -80,6 +90,11 @@ Java_org_apache_hadoop_io_compress_bzip2_Bzip2Decompressor_initIDs(
"Ljava/nio/Buffer;");
Bzip2Decompressor_directBufferSize = (*env)->GetFieldID(env, class,
"directBufferSize", "I");
+cleanup:
+ if(java_lib_name != NULL) {
+ (*env)->ReleaseStringUTFChars(env,libname,java_lib_name);
+ java_lib_name = NULL;
+ }
}
JNIEXPORT jlong JNICALL
@@ -237,9 +252,10 @@ Java_org_apache_hadoop_io_compress_bzip2_Bzip2Decompressor_end(
{
if (dlsym_BZ2_bzDecompressEnd(BZSTREAM(stream)) != BZ_OK) {
THROW(env, "java/lang/InternalError", 0);
- } else {
- free(BZSTREAM(stream));
}
+
+ free(BZSTREAM(stream));
+
}
/**