Index: /trunk/psLib/src/sys/psMemory.c
===================================================================
--- /trunk/psLib/src/sys/psMemory.c	(revision 1729)
+++ /trunk/psLib/src/sys/psMemory.c	(revision 1730)
@@ -9,6 +9,6 @@
 *  @author Robert Lupton, Princeton University
 *
-*  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-09-08 00:15:16 $
+*  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-09-08 21:06:00 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,5 +28,4 @@
 
 #include "psSysUtilsErrors.h"
-#define ERRORNAME_PREFIX PS_ERRORNAME_DOMAIN ".psMemory."
 
 #define P_PS_MEMMAGIC (void *)0xdeadbeef   // Magic number in psMemBlock header
@@ -103,5 +102,5 @@
 {
     if (ptr->refCounter < 1) {
-        psErrorMsg(ERRORNAME_PREFIX "memProblemCallbackDefault", false, PS_ERR_MEMORY_CORRUPTION,
+        psErrorMsg(PS_ERRORNAME_DOMAIN "memProblemCallbackDefault", false, PS_ERR_MEMORY_CORRUPTION,
                    PS_ERRORTEXT_psMemory_MULTIPLE_FREE,
                    ptr->id, ptr->file, ptr->lineno, file, lineno);
@@ -231,5 +230,5 @@
 
     if (m == NULL) {
-        psErrorMsg(ERRORNAME_PREFIX "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
+        psErrorMsg(PS_ERRORNAME_DOMAIN "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
                    PS_ERRORTEXT_psMemory_NULL_BLOCK);
         return 1;
@@ -238,5 +237,5 @@
     if (m->refCounter == 0) {
         // using an unreferenced block of memory, are you?
-        psErrorMsg(ERRORNAME_PREFIX "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
+        psErrorMsg(PS_ERRORNAME_DOMAIN "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
                    PS_ERRORTEXT_psMemory_DEREF_BLOCK_USE,
                    m->id);
@@ -245,5 +244,5 @@
 
     if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) {
-        psErrorMsg(ERRORNAME_PREFIX "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
+        psErrorMsg(PS_ERRORNAME_DOMAIN "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
                    PS_ERRORTEXT_psMemory_UNDERFLOW,
                    m->id);
@@ -251,5 +250,5 @@
     }
     if (*(void **)((int8_t *) (m + 1) + m->userMemorySize) != P_PS_MEMMAGIC) {
-        psErrorMsg(ERRORNAME_PREFIX "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
+        psErrorMsg(PS_ERRORNAME_DOMAIN "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
                    PS_ERRORTEXT_psMemory_OVERFLOW,
                    m->id);
@@ -419,4 +418,17 @@
 void p_psFree(void *vptr, const char *file, int lineno)
 {
+    if (vptr == NULL) {
+        return;
+    }
+    psMemBlock* ptr = ((psMemBlock* ) vptr) - 1;
+    if (ptr->refCounter < 1) {
+        psMemBlock* ptr = ((psMemBlock* ) vptr) - 1;
+
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psFree",PS_ERR_MEMORY_DEREF_USAGE,true,
+                   PS_ERRORTEXT_psMemory_MULTIPLE_FREE,
+                   ptr->id, ptr->file, ptr->lineno, file, lineno);
+
+        return;
+    }
     (void)p_psMemDecrRefCounter(vptr, file, lineno);    // this handles the free, if required.
 }
@@ -535,5 +547,4 @@
 
     if (ptr->refCounter > 1) {
-        // / XXX - Probably should have another mutex here.
         ptr->refCounter--;                 // multiple references, just decrement the count.
         pthread_mutex_unlock(&ptr->refCounterMutex);
Index: /trunk/psLib/src/sysUtils/psMemory.c
===================================================================
--- /trunk/psLib/src/sysUtils/psMemory.c	(revision 1729)
+++ /trunk/psLib/src/sysUtils/psMemory.c	(revision 1730)
@@ -9,6 +9,6 @@
 *  @author Robert Lupton, Princeton University
 *
-*  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-09-08 00:15:16 $
+*  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-09-08 21:06:00 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,5 +28,4 @@
 
 #include "psSysUtilsErrors.h"
-#define ERRORNAME_PREFIX PS_ERRORNAME_DOMAIN ".psMemory."
 
 #define P_PS_MEMMAGIC (void *)0xdeadbeef   // Magic number in psMemBlock header
@@ -103,5 +102,5 @@
 {
     if (ptr->refCounter < 1) {
-        psErrorMsg(ERRORNAME_PREFIX "memProblemCallbackDefault", false, PS_ERR_MEMORY_CORRUPTION,
+        psErrorMsg(PS_ERRORNAME_DOMAIN "memProblemCallbackDefault", false, PS_ERR_MEMORY_CORRUPTION,
                    PS_ERRORTEXT_psMemory_MULTIPLE_FREE,
                    ptr->id, ptr->file, ptr->lineno, file, lineno);
@@ -231,5 +230,5 @@
 
     if (m == NULL) {
-        psErrorMsg(ERRORNAME_PREFIX "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
+        psErrorMsg(PS_ERRORNAME_DOMAIN "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
                    PS_ERRORTEXT_psMemory_NULL_BLOCK);
         return 1;
@@ -238,5 +237,5 @@
     if (m->refCounter == 0) {
         // using an unreferenced block of memory, are you?
-        psErrorMsg(ERRORNAME_PREFIX "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
+        psErrorMsg(PS_ERRORNAME_DOMAIN "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
                    PS_ERRORTEXT_psMemory_DEREF_BLOCK_USE,
                    m->id);
@@ -245,5 +244,5 @@
 
     if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) {
-        psErrorMsg(ERRORNAME_PREFIX "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
+        psErrorMsg(PS_ERRORNAME_DOMAIN "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
                    PS_ERRORTEXT_psMemory_UNDERFLOW,
                    m->id);
@@ -251,5 +250,5 @@
     }
     if (*(void **)((int8_t *) (m + 1) + m->userMemorySize) != P_PS_MEMMAGIC) {
-        psErrorMsg(ERRORNAME_PREFIX "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
+        psErrorMsg(PS_ERRORNAME_DOMAIN "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION,
                    PS_ERRORTEXT_psMemory_OVERFLOW,
                    m->id);
@@ -419,4 +418,17 @@
 void p_psFree(void *vptr, const char *file, int lineno)
 {
+    if (vptr == NULL) {
+        return;
+    }
+    psMemBlock* ptr = ((psMemBlock* ) vptr) - 1;
+    if (ptr->refCounter < 1) {
+        psMemBlock* ptr = ((psMemBlock* ) vptr) - 1;
+
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psFree",PS_ERR_MEMORY_DEREF_USAGE,true,
+                   PS_ERRORTEXT_psMemory_MULTIPLE_FREE,
+                   ptr->id, ptr->file, ptr->lineno, file, lineno);
+
+        return;
+    }
     (void)p_psMemDecrRefCounter(vptr, file, lineno);    // this handles the free, if required.
 }
@@ -535,5 +547,4 @@
 
     if (ptr->refCounter > 1) {
-        // / XXX - Probably should have another mutex here.
         ptr->refCounter--;                 // multiple references, just decrement the count.
         pthread_mutex_unlock(&ptr->refCounterMutex);
