Index: /trunk/psLib/src/types/psMetadataConfig.c
===================================================================
--- /trunk/psLib/src/types/psMetadataConfig.c	(revision 9872)
+++ /trunk/psLib/src/types/psMetadataConfig.c	(revision 9873)
@@ -10,6 +10,6 @@
 *  @author Eric Van Alst, MHPCC
 *
-*  @version $Revision: 1.109 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-11-07 04:21:05 $
+*  @version $Revision: 1.110 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-11-07 04:35:21 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -1227,5 +1227,5 @@
 {
     // Check for NULL file name
-    PS_ASSERT_PTR_NON_NULL(filename,NULL);
+    PS_ASSERT_PTR_NON_NULL(filename, NULL);
 
     // Attempt to open specified file
@@ -1296,7 +1296,7 @@
                                   bool overwrite)
 {
-    psArray*            parseLevelInfoArray  = NULL;
-    psS32               nestingLevel         = 0;
-    p_psParseLevelInfo* topLevelInfo         = NULL;
+    bool allocedMD = false;
+
+    PS_ASSERT_PTR_NON_NULL(str, NULL);
 
     // Initialise nFail, if provided
@@ -1307,36 +1307,50 @@
     // Allocate metadata if necessary
     if (md == NULL) {
+        allocedMD = true;
         md = psMetadataAlloc();
     }
 
     // Allocate array to store parse level information
-    parseLevelInfoArray = psArrayAllocEmpty(INITIAL_LENGTH);
+    psArray *parseLevelInfoArray = psArrayAllocEmpty(INITIAL_LENGTH);
 
     // Set parse level info for the top level
-    topLevelInfo = p_psParseLevelInfoAlloc();
+    p_psParseLevelInfo *topLevelInfo = p_psParseLevelInfoAlloc();
     topLevelInfo->metadata = psMemIncrRefCounter(md);
-    parseLevelInfoArray = psArrayAdd(parseLevelInfoArray, 1, topLevelInfo);
+    psArrayAdd(parseLevelInfoArray, 0, topLevelInfo);
     psFree(topLevelInfo);
 
+    psList *doc = psStringSplit(str, "\n", false);
+    if (!doc) {
+        psError(PS_ERR_UNKNOWN, false, "failed to split string: %s", str);
+        psFree(parseLevelInfoArray);
+        if (allocedMD) {
+            psFree(md);
+        }
+        return NULL;
+    }
+    if (psListLength(doc) == 0) {
+        psError(PS_ERR_UNKNOWN, false, "string contained no lines");
+        psFree(doc);
+        psFree(parseLevelInfoArray);
+        if (allocedMD) {
+            psFree(md);
+        }
+        return NULL;
+    }
+
+    // clear the error stack so we can call psError(..., false, ...) and let
+    // errors from the parse loop accumulate
+    psErrorClear();
+
     // While loop to parse the file
-    psErrorClear();   // so we can call psError(..., false, ...)
-
-    psList *doc = psStringSplit(str, "\n", false);
-    if (!doc || doc->n == 0) {
-        if (doc != NULL)
-            psFree(doc);
-        psFree(parseLevelInfoArray);
-        psFree(md);
-        return NULL;
-    }
-
     long lineCount = 0;
     char *line = NULL;
+    psS32 nestingLevel  = 0;
     psListIterator *iter = psListIteratorAlloc(doc, 0, false);
-    while((line = psListGetAndIncrement(iter))) {
+    while ((line = psListGetAndIncrement(iter))) {
         lineCount++; // indexed from 1
 
-        if(!parseLine(&nestingLevel, parseLevelInfoArray, line, lineCount,
-                      overwrite)) {
+        if (!parseLine(&nestingLevel, parseLevelInfoArray, line, lineCount,
+                       overwrite)) {
             if (nFail != NULL) {
                 (*nFail)++;
