Index: trunk/psLib/src/sys/psMemory.c
===================================================================
--- trunk/psLib/src/sys/psMemory.c	(revision 19120)
+++ trunk/psLib/src/sys/psMemory.c	(revision 19128)
@@ -10,6 +10,6 @@
 *  @author Joshua Hoblitt, University of Hawaii
 *
-*  @version $Revision: 1.99 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-07-31 23:56:10 $
+*  @version $Revision: 1.100 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2008-08-20 02:00:20 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -81,6 +81,6 @@
 //      p_psMemAllocID -- rarely accessed
 //      p_psMemFreeID -- rarely accessed
-//      lastMemBlockAllocated 
-//      memid -- rarely accessby 
+//      lastMemBlockAllocated
+//      memid -- rarely accessby
 //      "the linked list of mem blocks"
 //
@@ -185,5 +185,5 @@
 // notify user when this block is allocated
 // XXX why was this not static, and why was it p_psMemAllocID?
-static psMemId p_psMemAllocID = 0;       
+static psMemId p_psMemAllocID = 0;
 
 // the above callback is only called if a specific psMemId is set with this function
@@ -327,5 +327,5 @@
 }
 
-// pointer to the last mem block that was allocated.  
+// pointer to the last mem block that was allocated.
 // This is the root of the entire memory list
 static psMemBlock *lastMemBlockAllocated = NULL;
@@ -341,5 +341,5 @@
     psMemBlock *memBlock = malloc(sizeof(psMemBlock) + size + sizeof(void *));
     if (memBlock == NULL) {
-	// this lock is only occasionally called in a given program (rarely fail malloc)
+        // this lock is only occasionally called in a given program (rarely fail malloc)
         MUTEX_LOCK(&memBlockListMutex);
         memBlock = memExhaustedCallback(size);
@@ -377,5 +377,6 @@
     void **bt = malloc(BACKTRACE_BUFFER_SIZE * sizeof(void *));
     if (bt == NULL) {
-        PS_MEM_ABORT(__func__, "Failed to allocate memory for backtrace buffer: %zd bytes at %s (%s:%d)", 32 * sizeof(void *), func, file, lineno);
+        PS_MEM_ABORT(__func__, "Failed to allocate memory for backtrace buffer: %zd bytes at %s (%s:%d)",
+                     32 * sizeof(void *), func, file, lineno);
     }
     *(size_t *)&memBlock->backtraceSize = backtrace(bt, BACKTRACE_BUFFER_SIZE);
@@ -403,15 +404,14 @@
 
     // insert the new block to the front of the memBlock linked-list
-    if (lastMemBlockAllocated != NULL) {
-	// exchange forward and backward references with the last allocated block
-	lastMemBlockAllocated->previousBlock = memBlock;
-	memBlock->nextBlock = lastMemBlockAllocated;
-    }
+    if (lastMemBlockAllocated) {
+        // exchange forward and backward references with the last allocated block
+        lastMemBlockAllocated->previousBlock = memBlock;
+    }
+    memBlock->nextBlock = lastMemBlockAllocated;
     lastMemBlockAllocated = memBlock;
 
     // Did the user ask to be informed about this allocation?
     if (memBlock->id == p_psMemAllocID) {
-        // p_psMemAllocID can only be changed while the memBlockList mutex is
-        // held
+        // p_psMemAllocID can only be changed while the memBlockList mutex is held
         p_psMemAllocID += memAllocCallback(memBlock);
     }
@@ -424,5 +424,5 @@
 
 /* internal routine to check the consistency of the allocated and/or free memory arena.
- * this is used by the user functions below (psMem{Set,Get}Deallocator, 
+ * this is used by the user functions below (psMem{Set,Get}Deallocator,
  * N.b. If the block wasn't allocated by psAlloc, it will appear corrupted
  */
@@ -537,5 +537,5 @@
     // this lock is frequently called in a given program
     MUTEX_LOCK(&memBlockListMutex);
-    
+
     psMemBlock *nextBlock = memBlock->nextBlock;
     psMemBlock *previousBlock = memBlock->previousBlock;
@@ -734,5 +734,6 @@
     HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
 
-    // XXX we probably need a MUTEX_LOCK here: otherwise, two functions can race on recCounter++ and refCounter--;
+    // XXX we probably need a MUTEX_LOCK here: otherwise, two functions can race on recCounter++ and
+    // refCounter--;
     memBlock->refCounter++;
 
@@ -741,11 +742,9 @@
     // this lock is probably not needed: if someone changes the callback ID in a different thread,
     // do we really care about really rarely getting this wrong?
-    // MUTEX_LOCK(&memBlockListMutex);
     if (memBlock->id == p_psMemAllocID) {
-	// XXX this is seriously bogus: why are we changing this value??
-        // p_psMemAllocID += memAllocCallback(memBlock);
-        memAllocCallback(memBlock);
-    }
-    // MUTEX_UNLOCK(&memBlockListMutex);
+        MUTEX_LOCK(&memBlockListMutex);
+        p_psMemAllocID += memAllocCallback(memBlock);
+        MUTEX_UNLOCK(&memBlockListMutex);
+    }
 
     return ptr;
@@ -807,11 +806,9 @@
 
         // Did the user ask to be informed about this deallocation?
-        // MUTEX_LOCK(&memBlockListMutex);
+        MUTEX_LOCK(&memBlockListMutex);
         if (memBlock->id == p_psMemFreeID) {
-	    // XXX why modify this?  this seems bogus
-            // p_psMemFreeID += memFreeCallback(memBlock);
-            memFreeCallback(memBlock);
-        }
-        // MUTEX_UNLOCK(&memBlockListMutex);
+            p_psMemFreeID += memFreeCallback(memBlock);
+        }
+        MUTEX_UNLOCK(&memBlockListMutex);
         return ptr;
     }
@@ -828,6 +825,5 @@
     // Did the user ask to be informed about this deallocation?
     if (memBlock->id == p_psMemFreeID) {
-        // p_psMemFreeID += memFreeCallback(ptr);
-        memFreeCallback(ptr);
+        p_psMemFreeID += memFreeCallback(ptr);
     }
 
