Index: /branches/jch-memory/psLib/src/sys/psError.c
===================================================================
--- /branches/jch-memory/psLib/src/sys/psError.c	(revision 10889)
+++ /branches/jch-memory/psLib/src/sys/psError.c	(revision 10890)
@@ -11,6 +11,6 @@
  *  @author Eric Van Alst, MHPCC
  *
- *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-24 22:52:56 $
+ *  @version $Revision: 1.41.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-01-03 21:43:57 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -98,4 +98,26 @@
 }
 
+// This function serves the same purpose of psErrorStackGet() accept it does
+// not alloc the error stack if it DOES NOT already exist.  Unlike
+// psErrorStackGet(), this function is NOT guarenteed to return a valid pointer
+// and it's return status must be checked.
+static psArray *psErrorStackGetNoAlloc(void)
+{
+    // check to see if the error stack key has been initialized
+    pthread_mutex_lock(&lockErrorStack);
+    if (errorStackKeyInitialized == false) {
+        return NULL;
+    }
+    pthread_mutex_unlock(&lockErrorStack);
+
+    // check to see if the error stack for this thread has been allocated
+    psArray *errorStack = NULL;
+    if ((errorStack = pthread_getspecific(errorStack_key)) == NULL) {
+        return NULL;
+    }
+
+    return errorStack;
+}
+
 static void psErrFree(psErr* err)
 {
@@ -260,7 +282,14 @@
 }
 
+// This function does not allocate any memory so it is safe to call from inside
+// of psMemory.c.  Do not allocate memory in function (or call any functions
+// that do) without first removing it's use from psMemory.c.
 void psErrorStackPrintV(FILE *fd, const char *format, va_list va)
 {
-    psArray *errorStack = psErrorStackGet();
+    psArray *errorStack = psErrorStackGetNoAlloc();
+    // do nothing if there error stack has not been allocated
+    if (!errorStack) {
+        return;
+    }
 
     vfprintf(fd, format, va);
