Explorar o código

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/trunk@1405149 13f79535-47bb-0310-9956-ffa450edef68
Todd Lipcon %!s(int64=12) %!d(string=hai) anos
pai
achega
a9e4b08f2b

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -539,6 +539,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

+ 18 - 23
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* 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, bld2);
+    (*env)->DeleteLocalRef(env, cluster);
     (*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:
-    (*env)->DeleteLocalRef(env, val.l);
-error_dlr_bld2:
-    (*env)->DeleteLocalRef(env, bld2);
-error_dlr_bld:
+error:
+    (*env)->DeleteLocalRef(env, cluster);
     (*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;
 }
 }