From aa12dd4f77c736ebed94aca7d29c2ca6427dbcf0 Mon Sep 17 00:00:00 2001 From: Todd Lipcon Date: Fri, 2 Nov 2012 20:35:54 +0000 Subject: [PATCH] HDFS-4132. When libwebhdfs is not enabled, nativeMiniDfsClient frees uninitialized memory. Contributed by Colin Patrick McCabe. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1405150 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../src/main/native/libhdfs/native_mini_dfs.c | 41 ++++++++----------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index b4f15daa7bf..94b8a3c2a87 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -190,6 +190,9 @@ Release 2.0.3-alpha - Unreleased HDFS-3804. TestHftpFileSystem fails intermittently with JDK7 (Trevor Robinson via daryn) + HDFS-4132. When libwebhdfs is not enabled, nativeMiniDfsClient frees + uninitialized memory (Colin Patrick McCabe via todd) + Release 2.0.2-alpha - 2012-09-07 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/native_mini_dfs.c b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/native_mini_dfs.c index 175d9471205..a1e786450f0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/native_mini_dfs.c +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/native_mini_dfs.c @@ -44,11 +44,11 @@ struct NativeMiniDfsCluster { struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf) { struct NativeMiniDfsCluster* cl = NULL; - jobject bld = NULL, bld2 = NULL, cobj = NULL; + jobject bld = NULL, cobj = NULL, cluster = NULL; jvalue val; JNIEnv *env = getJNIEnv(); jthrowable jthr; - jstring jconfStr; + jstring jconfStr = NULL; if (!env) { fprintf(stderr, "nmdCreate: unable to construct JNIEnv.\n"); @@ -63,14 +63,14 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf) if (jthr) { printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: new Configuration"); - goto error_free_cl; + goto error; } if (conf->webhdfsEnabled) { jthr = newJavaStr(env, DFS_WEBHDFS_ENABLED_KEY, &jconfStr); if (jthr) { printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: new String"); - goto error_dlr_cobj; + goto error; } jthr = invokeMethod(env, NULL, INSTANCE, cobj, HADOOP_CONF, "setBoolean", "(Ljava/lang/String;Z)V", @@ -78,7 +78,7 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf) if (jthr) { printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: Configuration::setBoolean"); - goto error_dlr_cobj; + goto error; } } jthr = constructNewObjectOfClass(env, &bld, MINIDFS_CLUSTER_BUILDER, @@ -86,58 +86,53 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf) if (jthr) { printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: NativeMiniDfsCluster#Builder#Builder"); - goto error_dlr_cobj; + goto error; } jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER, "format", "(Z)L" MINIDFS_CLUSTER_BUILDER ";", conf->doFormat); if (jthr) { printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: " "Builder::format"); - goto error_dlr_bld; + goto error; } - bld2 = val.l; + (*env)->DeleteLocalRef(env, val.l); if (conf->webhdfsEnabled) { - jthr = invokeMethod(env, &val, INSTANCE, bld2, MINIDFS_CLUSTER_BUILDER, + jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER, "nameNodeHttpPort", "(I)L" MINIDFS_CLUSTER_BUILDER ";", conf->namenodeHttpPort); if (jthr) { printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: " "Builder::nameNodeHttpPort"); - goto error_dlr_bld2; + goto error; } + (*env)->DeleteLocalRef(env, val.l); } jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER, "build", "()L" MINIDFS_CLUSTER ";"); if (jthr) { printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: Builder#build"); - goto error_dlr_bld2; + goto error; } - cl->obj = (*env)->NewGlobalRef(env, val.l); + cluster = val.l; + cl->obj = (*env)->NewGlobalRef(env, val.l); if (!cl->obj) { printPendingExceptionAndFree(env, PRINT_EXC_ALL, "nmdCreate: NewGlobalRef"); - goto error_dlr_val; + goto error; } - (*env)->DeleteLocalRef(env, val.l); - (*env)->DeleteLocalRef(env, bld2); + (*env)->DeleteLocalRef(env, cluster); (*env)->DeleteLocalRef(env, bld); (*env)->DeleteLocalRef(env, cobj); (*env)->DeleteLocalRef(env, jconfStr); return cl; -error_dlr_val: - (*env)->DeleteLocalRef(env, val.l); -error_dlr_bld2: - (*env)->DeleteLocalRef(env, bld2); -error_dlr_bld: +error: + (*env)->DeleteLocalRef(env, cluster); (*env)->DeleteLocalRef(env, bld); -error_dlr_cobj: (*env)->DeleteLocalRef(env, cobj); (*env)->DeleteLocalRef(env, jconfStr); -error_free_cl: free(cl); -error: return NULL; }