瀏覽代碼

HADOOP-11050. hconf.c: fix bug where we would sometimes not try to load multiple XML files from the same path

Colin Patrick Mccabe 10 年之前
父節點
當前提交
81e87f34b4

+ 1 - 1
hadoop-native-core/src/main/native/common/hconf-unit.c

@@ -125,7 +125,7 @@ static int test_hconf_xml(void)
     EXPECT_NULL(hconf_builder_alloc(&bld));
     EXPECT_NONNULL(bld);
     EXPECT_NO_HADOOP_ERR(hconf_builder_load_xmls(bld, TEST_XML_NAMES,
-            HCONF_XML_TEST_PATH ":" HCONF_XML_TEST_PATH "/.."));
+            HCONF_XML_TEST_PATH "/..:" HCONF_XML_TEST_PATH));
     EXPECT_NO_HADOOP_ERR(hconf_build(bld, &conf));
     EXPECT_NONNULL(conf);
     EXPECT_NULL(hconf_get(conf, "foo.empty"));

+ 5 - 3
hadoop-native-core/src/main/native/common/hconf.c

@@ -761,12 +761,12 @@ struct hadoop_err *hconf_builder_load_xmls(struct hconf_builder *bld,
     int ret, i;
     FILE *fp = NULL;
 
-    npathlist = strdup(pathlist);
-    if (!npathlist)
-        goto oom;
     // We need to read XML files in a certain order.  For example,
     // core-site.xml must be read in before hdfs-site.xml in libhdfs.
     for (i = 0; XMLS[i]; i++) {
+        npathlist = strdup(pathlist);
+        if (!npathlist)
+            goto oom;
         for (dir = strtok_r(npathlist, ":", &ptr); dir;
                     dir = strtok_r(NULL, ":", &ptr)) {
             if (asprintf(&path, "%s/%s", dir, XMLS[i]) < 0) {
@@ -790,6 +790,8 @@ struct hadoop_err *hconf_builder_load_xmls(struct hconf_builder *bld,
             free(path);
             path = NULL;
         }
+        free(npathlist);
+        npathlist = NULL;
     }
     err = NULL;
     goto done;