Index: /trunk/psLib/src/types/psMetadataConfig.c
===================================================================
--- /trunk/psLib/src/types/psMetadataConfig.c	(revision 9871)
+++ /trunk/psLib/src/types/psMetadataConfig.c	(revision 9872)
@@ -10,6 +10,6 @@
 *  @author Eric Van Alst, MHPCC
 *
-*  @version $Revision: 1.108 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-11-06 22:31:31 $
+*  @version $Revision: 1.109 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-11-07 04:21:05 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -1232,6 +1232,5 @@
     int fd = 0;
     fd = open(filename, O_RDONLY);
-    struct stat buf;                    // Results of stat() for file
-    if (fd < 0 || fstat(fd, &buf) != 0) {
+    if (fd < 0) {
         // XXX really should return strerror() here
         psError(PS_ERR_IO, true,
@@ -1241,5 +1240,7 @@
         return NULL;
     }
-    /*  This appears to be unreachable, but moving to check above just to be sure.
+
+    // Results of stat() for file
+    struct stat buf;
     if (fstat(fd, &buf) != 0) {
         psError(PS_ERR_IO, true, _("Unable to stat file '%s'.\n"), filename);
@@ -1247,23 +1248,26 @@
         return NULL;
     }
-    */
+
     // psMetadataConfigParse() is going to read the entire file into memory so
     // we're trying to be nice by allowing the VM to flush the file out of
-    // memory if need be.
-    // XXX yes, mmap is evil
-    void *file = mmap(0, (size_t)buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+    // memory if need be.  XXX we're adding 1 to buf.st_size here in case
+    // st_size / system page size has a remaineder of zero (in that case this
+    // magic trick may not work because there won't be any trailing \0s at the
+    // end of the page).
+    void *file = mmap(0, (size_t)buf.st_size + 1, PROT_READ, MAP_PRIVATE, fd, 0);
     if (file == MAP_FAILED) {
         psError(PS_ERR_IO, true, _("failed to mmap() file %s"), filename);
-        /*        if (close(fd) != 0) {
-                    // XXX really should return strerror() here
-                    psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
-                    return NULL;
-                }
-        */
-        close(fd);
+        if (close(fd) != 0) {
+            psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
+            return NULL;
+        }
         return NULL;
     }
 
     md = psMetadataConfigParse(md, nFail, (char *)file, overwrite);
+    if (!md) {
+        psError(PS_ERR_IO, true, _("failed to parse file '%s'"), filename);
+        return NULL;
+    }
 
     if (munmap(file, (size_t)buf.st_size) != 0) {
@@ -1273,16 +1277,15 @@
             // munmap() error
             psError(PS_ERR_IO, false, _("Failed to close file '%s'."), filename);
+            psFree(md);
             return NULL;
         }
     }
 
-    /*
     if (close(fd) != 0) {
-        // XXX really should return strerror() here
         psError(PS_ERR_IO, true, _("Failed to close file '%s'."), filename);
+        psFree(md);
         return NULL;
     }
-    */
-    close(fd);
+
     return md;
 }
