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
This commit is contained in:
Todd Lipcon 2012-11-02 20:35:54 +00:00
parent 11822fb8ab
commit aa12dd4f77
2 changed files with 21 additions and 23 deletions

View File

@ -190,6 +190,9 @@ Release 2.0.3-alpha - Unreleased
HDFS-3804. TestHftpFileSystem fails intermittently with JDK7 HDFS-3804. TestHftpFileSystem fails intermittently with JDK7
(Trevor Robinson via daryn) (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 Release 2.0.2-alpha - 2012-09-07
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -44,11 +44,11 @@ struct NativeMiniDfsCluster {
struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf) struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
{ {
struct NativeMiniDfsCluster* cl = NULL; struct NativeMiniDfsCluster* cl = NULL;
jobject bld = NULL, bld2 = NULL, cobj = NULL; jobject bld = NULL, cobj = NULL, cluster = NULL;
jvalue val; jvalue val;
JNIEnv *env = getJNIEnv(); JNIEnv *env = getJNIEnv();
jthrowable jthr; jthrowable jthr;
jstring jconfStr; jstring jconfStr = NULL;
if (!env) { if (!env) {
fprintf(stderr, "nmdCreate: unable to construct JNIEnv.\n"); fprintf(stderr, "nmdCreate: unable to construct JNIEnv.\n");
@ -63,14 +63,14 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
if (jthr) { if (jthr) {
printExceptionAndFree(env, jthr, PRINT_EXC_ALL, printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
"nmdCreate: new Configuration"); "nmdCreate: new Configuration");
goto error_free_cl; goto error;
} }
if (conf->webhdfsEnabled) { if (conf->webhdfsEnabled) {
jthr = newJavaStr(env, DFS_WEBHDFS_ENABLED_KEY, &jconfStr); jthr = newJavaStr(env, DFS_WEBHDFS_ENABLED_KEY, &jconfStr);
if (jthr) { if (jthr) {
printExceptionAndFree(env, jthr, PRINT_EXC_ALL, printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
"nmdCreate: new String"); "nmdCreate: new String");
goto error_dlr_cobj; goto error;
} }
jthr = invokeMethod(env, NULL, INSTANCE, cobj, HADOOP_CONF, jthr = invokeMethod(env, NULL, INSTANCE, cobj, HADOOP_CONF,
"setBoolean", "(Ljava/lang/String;Z)V", "setBoolean", "(Ljava/lang/String;Z)V",
@ -78,7 +78,7 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
if (jthr) { if (jthr) {
printExceptionAndFree(env, jthr, PRINT_EXC_ALL, printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
"nmdCreate: Configuration::setBoolean"); "nmdCreate: Configuration::setBoolean");
goto error_dlr_cobj; goto error;
} }
} }
jthr = constructNewObjectOfClass(env, &bld, MINIDFS_CLUSTER_BUILDER, jthr = constructNewObjectOfClass(env, &bld, MINIDFS_CLUSTER_BUILDER,
@ -86,58 +86,53 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
if (jthr) { if (jthr) {
printExceptionAndFree(env, jthr, PRINT_EXC_ALL, printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
"nmdCreate: NativeMiniDfsCluster#Builder#Builder"); "nmdCreate: NativeMiniDfsCluster#Builder#Builder");
goto error_dlr_cobj; goto error;
} }
jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER, jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
"format", "(Z)L" MINIDFS_CLUSTER_BUILDER ";", conf->doFormat); "format", "(Z)L" MINIDFS_CLUSTER_BUILDER ";", conf->doFormat);
if (jthr) { if (jthr) {
printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: " printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: "
"Builder::format"); "Builder::format");
goto error_dlr_bld; goto error;
} }
bld2 = val.l; (*env)->DeleteLocalRef(env, val.l);
if (conf->webhdfsEnabled) { 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 ";", "nameNodeHttpPort", "(I)L" MINIDFS_CLUSTER_BUILDER ";",
conf->namenodeHttpPort); conf->namenodeHttpPort);
if (jthr) { if (jthr) {
printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: " printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: "
"Builder::nameNodeHttpPort"); "Builder::nameNodeHttpPort");
goto error_dlr_bld2; goto error;
} }
(*env)->DeleteLocalRef(env, val.l);
} }
jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER, jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
"build", "()L" MINIDFS_CLUSTER ";"); "build", "()L" MINIDFS_CLUSTER ";");
if (jthr) { if (jthr) {
printExceptionAndFree(env, jthr, PRINT_EXC_ALL, printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
"nmdCreate: Builder#build"); "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) { if (!cl->obj) {
printPendingExceptionAndFree(env, PRINT_EXC_ALL, printPendingExceptionAndFree(env, PRINT_EXC_ALL,
"nmdCreate: NewGlobalRef"); "nmdCreate: NewGlobalRef");
goto error_dlr_val; goto error;
} }
(*env)->DeleteLocalRef(env, val.l); (*env)->DeleteLocalRef(env, cluster);
(*env)->DeleteLocalRef(env, bld2);
(*env)->DeleteLocalRef(env, bld); (*env)->DeleteLocalRef(env, bld);
(*env)->DeleteLocalRef(env, cobj); (*env)->DeleteLocalRef(env, cobj);
(*env)->DeleteLocalRef(env, jconfStr); (*env)->DeleteLocalRef(env, jconfStr);
return cl; return cl;
error_dlr_val: error:
(*env)->DeleteLocalRef(env, val.l); (*env)->DeleteLocalRef(env, cluster);
error_dlr_bld2:
(*env)->DeleteLocalRef(env, bld2);
error_dlr_bld:
(*env)->DeleteLocalRef(env, bld); (*env)->DeleteLocalRef(env, bld);
error_dlr_cobj:
(*env)->DeleteLocalRef(env, cobj); (*env)->DeleteLocalRef(env, cobj);
(*env)->DeleteLocalRef(env, jconfStr); (*env)->DeleteLocalRef(env, jconfStr);
error_free_cl:
free(cl); free(cl);
error:
return NULL; return NULL;
} }