Index: /trunk/psLib/src/sys/psMemory.c
===================================================================
--- /trunk/psLib/src/sys/psMemory.c	(revision 472)
+++ /trunk/psLib/src/sys/psMemory.c	(revision 473)
@@ -8,6 +8,6 @@
  *  @author Robert Lupton, Princeton University
  *
- *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-04-20 03:08:35 $
+ *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-04-20 03:10:31 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -39,5 +39,5 @@
 static void *memExhaustedCallbackDefault(size_t size)
 {
-  return NULL;
+    return NULL;
 }
 
@@ -46,16 +46,13 @@
 psMemExhaustedCallback psMemExhaustedSetCallback(psMemExhaustedCallback func)
 {
-  psMemExhaustedCallback old = memExhaustedCallback;
-
-  if (func != NULL)
-    {
-      memExhaustedCallback = func;
-    }
-  else
-    {
-      memExhaustedCallback = memExhaustedCallbackDefault;
-    }
-
-  return old;
+    psMemExhaustedCallback old = memExhaustedCallback;
+
+    if (func != NULL) {
+        memExhaustedCallback = func;
+    } else {
+        memExhaustedCallback = memExhaustedCallbackDefault;
+    }
+
+    return old;
 }
 
@@ -63,22 +60,18 @@
                                       const char *file, int lineno)
 {
-  checkMemBlock(ptr, __func__);
-
-  if (ptr->refCounter <= 0)
-    {
-      psError(__func__,
-              "Block %ld allocated at %s:%d freed more than once at %s:%d\n",
-              ptr->id, ptr->file, ptr->lineno, file, lineno);
-    }
-  else if (ptr->refCounter > 1)
-    {
-      psError(__func__,
-              "Block %ld allocated at %s:%d freed while still referenced at %s:%d\n",
-              ptr->id, ptr->file, ptr->lineno, file, lineno);
-    }
-
-  if (lineno > 0)
-    {
-      psAbort(__func__, "Detected a problem in the memory system at %s:%d", file, lineno);
+    checkMemBlock(ptr, __func__);
+
+    if (ptr->refCounter <= 0) {
+        psError(__func__,
+                "Block %ld allocated at %s:%d freed more than once at %s:%d\n",
+                ptr->id, ptr->file, ptr->lineno, file, lineno);
+    } else if (ptr->refCounter > 1) {
+        psError(__func__,
+                "Block %ld allocated at %s:%d freed while still referenced at %s:%d\n",
+                ptr->id, ptr->file, ptr->lineno, file, lineno);
+    }
+
+    if (lineno > 0) {
+        psAbort(__func__, "Detected a problem in the memory system at %s:%d", file, lineno);
     }
 }
@@ -87,16 +80,13 @@
 psMemProblemCallback psMemProblemSetCallback(psMemProblemCallback func)
 {
-  psMemProblemCallback old = memProblemCallback;
-
-  if (func != NULL)
-    {
-      memProblemCallback = func;
-    }
-  else
-    {
-      memProblemCallback = memProblemCallbackDefault;
-    }
-
-  return old;
+    psMemProblemCallback old = memProblemCallback;
+
+    if (func != NULL) {
+        memProblemCallback = func;
+    } else {
+        memProblemCallback = memProblemCallbackDefault;
+    }
+
+    return old;
 }
 /*
@@ -110,16 +100,16 @@
 long psMemSetAllocateID(long id) // set p_psMemAllocateID to id
 {
-  long old = p_psMemAllocateID;
-  p_psMemAllocateID = id;
-
-  return old;
+    long old = p_psMemAllocateID;
+    p_psMemAllocateID = id;
+
+    return old;
 }
 
 long psMemSetFreeID(long id)  // set p_psMemFreeID to id
 {
-  long old = p_psMemFreeID;
-  p_psMemFreeID = id;
-
-  return old;
+    long old = p_psMemFreeID;
+    p_psMemFreeID = id;
+
+    return old;
 }
 
@@ -132,14 +122,14 @@
 static long memAllocateCallbackDefault(const psMemBlock *ptr)
 {
-  static int incr = 0;  // "p_psMemAllocateID += incr"
-
-  return incr;
+    static int incr = 0;  // "p_psMemAllocateID += incr"
+
+    return incr;
 }
 
 static long memFreeCallbackDefault(const psMemBlock *ptr)
 {
-  static int incr = 0;  // "p_psMemFreeID += incr"
-
-  return incr;
+    static int incr = 0;  // "p_psMemFreeID += incr"
+
+    return incr;
 }
 
@@ -152,32 +142,26 @@
 psMemAllocateCallback psMemAllocateSetCallback(psMemAllocateCallback func)
 {
-  psMemFreeCallback old = memAllocateCallback;
-
-  if (func != NULL)
-    {
-      memAllocateCallback =  func;
-    }
-  else
-    {
-      memAllocateCallback = memAllocateCallbackDefault;
-    }
-
-  return old;
+    psMemFreeCallback old = memAllocateCallback;
+
+    if (func != NULL) {
+        memAllocateCallback =  func;
+    } else {
+        memAllocateCallback = memAllocateCallbackDefault;
+    }
+
+    return old;
 }
 
 psMemFreeCallback psMemFreeSetCallback(psMemFreeCallback func)
 {
-  psMemFreeCallback old = memFreeCallback;
-
-  if (func != NULL)
-    {
-      memFreeCallback = func;
-    }
-  else
-    {
-      memFreeCallback = memFreeCallbackDefault;
-    }
-
-  return old;
+    psMemFreeCallback old = memFreeCallback;
+
+    if (func != NULL) {
+        memFreeCallback = func;
+    } else {
+        memFreeCallback = memFreeCallbackDefault;
+    }
+
+    return old;
 }
 
@@ -187,5 +171,5 @@
 int psMemGetId(void)
 {
-  return memid + 1;
+    return memid + 1;
 }
 
@@ -201,130 +185,115 @@
               const char* funcName)
 {
-  // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked,
-  // we shouldn't call such things as p_psAlloc/p_psFree here.
-
-  if (m == NULL)
-    {
-      psError(funcName,"Memory Corruption: NULL memory block found.");
-      return(1);
-    }
-
-  if (!ALIGNED(m))
-    {
-      psError(funcName, "psMemCheckCorruption: non-aligned memory block");
-      return(1);
-    }
-
-  if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC)
-    {
-      psError(funcName, "psMemCheckCorruption: memory block %ld is corrupted", m->id);
-      return(1);
-    }
-
-  return(0);
+    // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked,
+    // we shouldn't call such things as p_psAlloc/p_psFree here.
+
+    if (m == NULL) {
+        psError(funcName,"Memory Corruption: NULL memory block found.");
+        return(1);
+    }
+
+    if (!ALIGNED(m)) {
+        psError(funcName, "psMemCheckCorruption: non-aligned memory block");
+        return(1);
+    }
+
+    if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) {
+        psError(funcName, "psMemCheckCorruption: memory block %ld is corrupted", m->id);
+        return(1);
+    }
+
+    return(0);
 }
 
 int psMemCheckCorruption(int abort_on_error)
 {
-  int nbad = 0;                       // number of bad blocks
-
-  // get exclusive access to the memBlock list to avoid it changing on us while we use it.
-  pthread_mutex_lock(&memBlockListMutex);
-
-  for (psMemBlock* iter=lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock)
-    {
-      if (checkMemBlock(iter, __func__))
-        {
-          nbad++;
-
-          memProblemCallback(iter, __func__, __LINE__);
-
-          if (abort_on_error)
-            {
-              // release the lock on the memblock list
-              pthread_mutex_unlock(&memBlockListMutex);
-              psAbort(__func__, "Detected memory corruption");
-              return nbad;
-            }
-        }
-    }
-
-  // release the lock on the memblock list
-  pthread_mutex_unlock(&memBlockListMutex);
-  return nbad;
+    int nbad = 0;                       // number of bad blocks
+
+    // get exclusive access to the memBlock list to avoid it changing on us while we use it.
+    pthread_mutex_lock(&memBlockListMutex);
+
+    for (psMemBlock* iter=lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock) {
+        if (checkMemBlock(iter, __func__)) {
+            nbad++;
+
+            memProblemCallback(iter, __func__, __LINE__);
+
+            if (abort_on_error) {
+                // release the lock on the memblock list
+                pthread_mutex_unlock(&memBlockListMutex);
+                psAbort(__func__, "Detected memory corruption");
+                return nbad;
+            }
+        }
+    }
+
+    // release the lock on the memblock list
+    pthread_mutex_unlock(&memBlockListMutex);
+    return nbad;
 }
 
 void *p_psAlloc(size_t size, const char *file, int lineno)
 {
-  psMemBlock *ptr = malloc(sizeof(psMemBlock) + size);
-
-  if (ptr == NULL)
-    {
-      ptr = memExhaustedCallback(size);
-      if (ptr == NULL)
-        {
-          psAbort(__func__, "Failed to allocate %ld bytes at %s:%d",
-                  size, file, lineno);
-        }
-    }
-
-  *(unsigned long*)&ptr->id = ++memid;
-  ptr->file = file;
-  *(unsigned int*)&ptr->lineno = lineno;
-  ptr->startblock = P_PS_MEMMAGIC;
-  ptr->endblock = P_PS_MEMMAGIC;
-  ptr->refCounter = 1;                // one user so far
-
-  // need exclusive access of the memory block list now...
-  pthread_mutex_lock(&memBlockListMutex);
-
-  // insert the new block to the front of the memBlock linked-list
-  ptr->previousBlock = NULL;
-  ptr->nextBlock = lastMemBlockAllocated;
-  if (ptr->nextBlock != NULL)
-    {
-      ptr->nextBlock->previousBlock = ptr;
-    }
-  lastMemBlockAllocated = ptr;
-
-  pthread_mutex_unlock(&memBlockListMutex);
-
-  //  Did the user ask to be informed about this allocation?
-  if (ptr->id == p_psMemAllocateID)
-    {
-      p_psMemAllocateID += memAllocateCallback(ptr);
-    }
-
-  // And return the user the memory that they allocated
-  return ptr + 1;   // user memory
+    psMemBlock *ptr = malloc(sizeof(psMemBlock) + size);
+
+    if (ptr == NULL) {
+        ptr = memExhaustedCallback(size);
+        if (ptr == NULL) {
+            psAbort(__func__, "Failed to allocate %ld bytes at %s:%d",
+                    size, file, lineno);
+        }
+    }
+
+    *(unsigned long*)&ptr->id = ++memid;
+    ptr->file = file;
+    *(unsigned int*)&ptr->lineno = lineno;
+    ptr->startblock = P_PS_MEMMAGIC;
+    ptr->endblock = P_PS_MEMMAGIC;
+    ptr->refCounter = 1;                // one user so far
+
+    // need exclusive access of the memory block list now...
+    pthread_mutex_lock(&memBlockListMutex);
+
+    // insert the new block to the front of the memBlock linked-list
+    ptr->previousBlock = NULL;
+    ptr->nextBlock = lastMemBlockAllocated;
+    if (ptr->nextBlock != NULL) {
+        ptr->nextBlock->previousBlock = ptr;
+    }
+    lastMemBlockAllocated = ptr;
+
+    pthread_mutex_unlock(&memBlockListMutex);
+
+    //  Did the user ask to be informed about this allocation?
+    if (ptr->id == p_psMemAllocateID) {
+        p_psMemAllocateID += memAllocateCallback(ptr);
+    }
+
+    // And return the user the memory that they allocated
+    return ptr + 1;   // user memory
 }
 
 void *p_psRealloc(void *vptr, size_t size, const char *file, int lineno)
 {
-  if (vptr == NULL)
-    {
-      return p_psAlloc(size, file, lineno);
-    }
-  else
-    {
-      psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-      pthread_mutex_lock(&memBlockListMutex);
-
-      ptr = (psMemBlock*)realloc(ptr, sizeof(psMemBlock) + size);
-
-      // the block location may have changed, so fix the linked list addresses.
-      if (ptr->nextBlock != NULL)
-        {
-          ptr->nextBlock->previousBlock = ptr;
-        }
-      if (ptr->previousBlock != NULL)
-        {
-          ptr->previousBlock->nextBlock = ptr;
-        }
-
-      pthread_mutex_unlock(&memBlockListMutex);
-
-      return ptr + 1;   // usr memory
+    if (vptr == NULL) {
+        return p_psAlloc(size, file, lineno);
+    } else {
+        psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
+
+        pthread_mutex_lock(&memBlockListMutex);
+
+        ptr = (psMemBlock*)realloc(ptr, sizeof(psMemBlock) + size);
+
+        // the block location may have changed, so fix the linked list addresses.
+        if (ptr->nextBlock != NULL) {
+            ptr->nextBlock->previousBlock = ptr;
+        }
+        if (ptr->previousBlock != NULL) {
+            ptr->previousBlock->nextBlock = ptr;
+        }
+
+        pthread_mutex_unlock(&memBlockListMutex);
+
+        return ptr + 1;   // usr memory
     }
 }
@@ -332,51 +301,40 @@
 void p_psFree(void *vptr, const char *file, int lineno)
 {
-  if (vptr == NULL)
-    {
-      return;
-    }
-
-  psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-  // Did the user ask to be informed about this deallocation?
-  if (ptr->id == p_psMemFreeID)
-    {
-      p_psMemFreeID += memFreeCallback(ptr);
-    }
-
-  if (checkMemBlock(ptr, "psFree") != 0)
-    {
-      memProblemCallback(ptr, file, lineno); // we may not own this block; don't free it
-    }
-  else
-    {
-      if (ptr->refCounter > 1)
-        {
-          psError(__func__,"The buffer being freed is referenced elsewhere. "
-                  "Buffer's reference count was decremented instead.");
-          ptr->refCounter--;
-          memProblemCallback(ptr, file, lineno);
-        }
-      else
-        {
-
-          // cut the memBlock out of the memBlock list
-          pthread_mutex_lock(&memBlockListMutex);
-          if (ptr->nextBlock != NULL)
-            {
-              ptr->nextBlock->previousBlock = ptr->previousBlock;
-            }
-          if (ptr->previousBlock != NULL)
-            {
-              ptr->previousBlock->nextBlock = ptr->nextBlock;
-            }
-          if (lastMemBlockAllocated == ptr)
-            {
-              lastMemBlockAllocated = ptr->nextBlock;
-            }
-
-          pthread_mutex_unlock(&memBlockListMutex);
-
-          free(ptr);
+    if (vptr == NULL) {
+        return;
+    }
+
+    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
+
+    // Did the user ask to be informed about this deallocation?
+    if (ptr->id == p_psMemFreeID) {
+        p_psMemFreeID += memFreeCallback(ptr);
+    }
+
+    if (checkMemBlock(ptr, "psFree") != 0) {
+        memProblemCallback(ptr, file, lineno); // we may not own this block; don't free it
+    } else {
+        if (ptr->refCounter > 1) {
+            psError(__func__,"The buffer being freed is referenced elsewhere. "
+                    "Buffer's reference count was decremented instead.");
+            ptr->refCounter--;
+            memProblemCallback(ptr, file, lineno);
+        } else {
+
+            // cut the memBlock out of the memBlock list
+            pthread_mutex_lock(&memBlockListMutex);
+            if (ptr->nextBlock != NULL) {
+                ptr->nextBlock->previousBlock = ptr->previousBlock;
+            }
+            if (ptr->previousBlock != NULL) {
+                ptr->previousBlock->nextBlock = ptr->nextBlock;
+            }
+            if (lastMemBlockAllocated == ptr) {
+                lastMemBlockAllocated = ptr->nextBlock;
+            }
+
+            pthread_mutex_unlock(&memBlockListMutex);
+
+            free(ptr);
         }
     }
@@ -387,59 +345,54 @@
  */
 int psMemCheckLeaks(
-  int id0,                            // don't list blocks with id < id0
-  psMemBlock ***arr,                  // pointer to array of pointers to leaked blocks, or NULL
-  FILE *fd)                           // print list of leaks to fd (or NULL)
-{
-  int nleak = 0;
-  int j = 0;
-
-  pthread_mutex_lock(&memBlockListMutex);
-
-  for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock)
-    {
-      if ( (iter->refCounter > 0) && (iter->id >= id0) )
-        {
-          nleak++;
-
-          if (fd != NULL)
-            {
-              if (nleak == 1)
-                {
-                  fprintf(fd, "   %20s:line ID\n", "file");
+    int id0,                            // don't list blocks with id < id0
+    psMemBlock ***arr,                  // pointer to array of pointers to leaked blocks, or NULL
+    FILE *fd)                           // print list of leaks to fd (or NULL)
+{
+    int nleak = 0;
+    int j = 0;
+
+    pthread_mutex_lock(&memBlockListMutex);
+
+    for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock)
+    {
+        if ( (iter->refCounter > 0) && (iter->id >= id0) ) {
+            nleak++;
+
+            if (fd != NULL) {
+                if (nleak == 1) {
+                    fprintf(fd, "   %20s:line ID\n", "file");
                 }
 
-              fprintf(fd, "   %20s:%-4d %ld\n", iter->file, iter->lineno, iter->id);
-            }
-        }
-    }
-
-  pthread_mutex_unlock(&memBlockListMutex);
-
-  if (nleak == 0 || arr == NULL)
-    {
-      return nleak;
-    }
-
-  p_psFree(*arr,__FILE__, __LINE__);  // Don't generate a memory leak!
-
-  *arr = p_psAlloc(nleak*sizeof(psMemBlock), __FILE__, __LINE__);
-
-  pthread_mutex_lock(&memBlockListMutex);
-
-  for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock)
-    {
-      if ( (iter->refCounter > 0) && (iter->id >= id0) )
-        {
-          (*arr)[j++] = iter;
-          if (j == nleak)
-            { // found them all
-              break;
-            }
-        }
-    }
-
-  pthread_mutex_unlock(&memBlockListMutex);
-
-  return nleak;
+                fprintf(fd, "   %20s:%-4d %ld\n", iter->file, iter->lineno, iter->id);
+            }
+        }
+    }
+
+    pthread_mutex_unlock(&memBlockListMutex);
+
+    if (nleak == 0 || arr == NULL)
+    {
+        return nleak;
+    }
+
+    p_psFree(*arr,__FILE__, __LINE__);  // Don't generate a memory leak!
+
+    *arr = p_psAlloc(nleak*sizeof(psMemBlock), __FILE__, __LINE__);
+
+    pthread_mutex_lock(&memBlockListMutex);
+
+    for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock)
+    {
+        if ( (iter->refCounter > 0) && (iter->id >= id0) ) {
+            (*arr)[j++] = iter;
+            if (j == nleak) { // found them all
+                break;
+            }
+        }
+    }
+
+    pthread_mutex_unlock(&memBlockListMutex);
+
+    return nleak;
 }
 
@@ -449,49 +402,49 @@
 int psMemGetRefCounter(void *vptr) // return refCounter
 {
-  psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-  if (checkMemBlock(ptr, __func__) != 0)
-    {
-      memProblemCallback(ptr, __func__, __LINE__);
-    }
-
-  return ptr->refCounter;
+    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
+
+    if (checkMemBlock(ptr, __func__) != 0)
+    {
+        memProblemCallback(ptr, __func__, __LINE__);
+    }
+
+    return ptr->refCounter;
 }
 
 void *psMemIncrRefCounter(void *vptr) // increment and return refCounter
 {
-  if (vptr == NULL)
-    {
-      return vptr;
-    }
-
-  psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-  if (checkMemBlock(ptr, __func__))
-    {
-      memProblemCallback(ptr, __func__, __LINE__);
-    }
-
-  ptr->refCounter++;
-
-  return vptr;
+    if (vptr == NULL)
+    {
+        return vptr;
+    }
+
+    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
+
+    if (checkMemBlock(ptr, __func__))
+    {
+        memProblemCallback(ptr, __func__, __LINE__);
+    }
+
+    ptr->refCounter++;
+
+    return vptr;
 }
 
 void *psMemDecrRefCounter(void *vptr) // decrement and return refCounter
 {
-  if (vptr == NULL)
-    {
-      return vptr;
-    }
-
-  psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-  if (checkMemBlock(ptr, __func__))
-    {
-      memProblemCallback(ptr, __func__, __LINE__);
-    }
-
-  ptr->refCounter--;
-
-  return vptr;
-}
+    if (vptr == NULL)
+    {
+        return vptr;
+    }
+
+    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
+
+    if (checkMemBlock(ptr, __func__))
+    {
+        memProblemCallback(ptr, __func__, __LINE__);
+    }
+
+    ptr->refCounter--;
+
+    return vptr;
+}
Index: /trunk/psLib/src/sysUtils/psMemory.c
===================================================================
--- /trunk/psLib/src/sysUtils/psMemory.c	(revision 472)
+++ /trunk/psLib/src/sysUtils/psMemory.c	(revision 473)
@@ -8,6 +8,6 @@
  *  @author Robert Lupton, Princeton University
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-04-20 03:08:16 $
+ *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-04-20 03:08:35 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -39,5 +39,5 @@
 static void *memExhaustedCallbackDefault(size_t size)
 {
-    return NULL;
+  return NULL;
 }
 
@@ -46,16 +46,16 @@
 psMemExhaustedCallback psMemExhaustedSetCallback(psMemExhaustedCallback func)
 {
-    psMemExhaustedCallback old = memExhaustedCallback;
-
-    if (func != NULL)
-    {
-        memExhaustedCallback = func;
-    }
-    else
-    {
-        memExhaustedCallback = memExhaustedCallbackDefault;
-    }
-
-    return old;
+  psMemExhaustedCallback old = memExhaustedCallback;
+
+  if (func != NULL)
+    {
+      memExhaustedCallback = func;
+    }
+  else
+    {
+      memExhaustedCallback = memExhaustedCallbackDefault;
+    }
+
+  return old;
 }
 
@@ -63,22 +63,22 @@
                                       const char *file, int lineno)
 {
-    checkMemBlock(ptr, __func__);
-
-    if (ptr->refCounter <= 0)
-    {
-        psError(__func__,
-                "Block %ld allocated at %s:%d freed more than once at %s:%d\n",
-                ptr->id, ptr->file, ptr->lineno, file, lineno);
-    }
-    else if (ptr->refCounter > 1)
-    {
-        psError(__func__,
-                "Block %ld allocated at %s:%d freed while still referenced at %s:%d\n",
-                ptr->id, ptr->file, ptr->lineno, file, lineno);
-    }
-
-    if (lineno > 0)
-    {
-        psAbort(__func__, "Detected a problem in the memory system at %s:%d", file, lineno);
+  checkMemBlock(ptr, __func__);
+
+  if (ptr->refCounter <= 0)
+    {
+      psError(__func__,
+              "Block %ld allocated at %s:%d freed more than once at %s:%d\n",
+              ptr->id, ptr->file, ptr->lineno, file, lineno);
+    }
+  else if (ptr->refCounter > 1)
+    {
+      psError(__func__,
+              "Block %ld allocated at %s:%d freed while still referenced at %s:%d\n",
+              ptr->id, ptr->file, ptr->lineno, file, lineno);
+    }
+
+  if (lineno > 0)
+    {
+      psAbort(__func__, "Detected a problem in the memory system at %s:%d", file, lineno);
     }
 }
@@ -87,16 +87,16 @@
 psMemProblemCallback psMemProblemSetCallback(psMemProblemCallback func)
 {
-    psMemProblemCallback old = memProblemCallback;
-
-    if (func != NULL)
-    {
-        memProblemCallback = func;
-    }
-    else
-    {
-        memProblemCallback = memProblemCallbackDefault;
-    }
-
-    return old;
+  psMemProblemCallback old = memProblemCallback;
+
+  if (func != NULL)
+    {
+      memProblemCallback = func;
+    }
+  else
+    {
+      memProblemCallback = memProblemCallbackDefault;
+    }
+
+  return old;
 }
 /*
@@ -110,16 +110,16 @@
 long psMemSetAllocateID(long id) // set p_psMemAllocateID to id
 {
-    long old = p_psMemAllocateID;
-    p_psMemAllocateID = id;
-
-    return old;
+  long old = p_psMemAllocateID;
+  p_psMemAllocateID = id;
+
+  return old;
 }
 
 long psMemSetFreeID(long id)  // set p_psMemFreeID to id
 {
-    long old = p_psMemFreeID;
-    p_psMemFreeID = id;
-
-    return old;
+  long old = p_psMemFreeID;
+  p_psMemFreeID = id;
+
+  return old;
 }
 
@@ -132,14 +132,14 @@
 static long memAllocateCallbackDefault(const psMemBlock *ptr)
 {
-    static int incr = 0;  // "p_psMemAllocateID += incr"
-
-    return incr;
+  static int incr = 0;  // "p_psMemAllocateID += incr"
+
+  return incr;
 }
 
 static long memFreeCallbackDefault(const psMemBlock *ptr)
 {
-    static int incr = 0;  // "p_psMemFreeID += incr"
-
-    return incr;
+  static int incr = 0;  // "p_psMemFreeID += incr"
+
+  return incr;
 }
 
@@ -152,32 +152,32 @@
 psMemAllocateCallback psMemAllocateSetCallback(psMemAllocateCallback func)
 {
-    psMemFreeCallback old = memAllocateCallback;
-
-    if (func != NULL)
-    {
-        memAllocateCallback =  func;
-    }
-    else
-    {
-        memAllocateCallback = memAllocateCallbackDefault;
-    }
-
-    return old;
+  psMemFreeCallback old = memAllocateCallback;
+
+  if (func != NULL)
+    {
+      memAllocateCallback =  func;
+    }
+  else
+    {
+      memAllocateCallback = memAllocateCallbackDefault;
+    }
+
+  return old;
 }
 
 psMemFreeCallback psMemFreeSetCallback(psMemFreeCallback func)
 {
-    psMemFreeCallback old = memFreeCallback;
-
-    if (func != NULL)
-    {
-        memFreeCallback = func;
-    }
-    else
-    {
-        memFreeCallback = memFreeCallbackDefault;
-    }
-
-    return old;
+  psMemFreeCallback old = memFreeCallback;
+
+  if (func != NULL)
+    {
+      memFreeCallback = func;
+    }
+  else
+    {
+      memFreeCallback = memFreeCallbackDefault;
+    }
+
+  return old;
 }
 
@@ -187,5 +187,5 @@
 int psMemGetId(void)
 {
-    return memid + 1;
+  return memid + 1;
 }
 
@@ -201,130 +201,130 @@
               const char* funcName)
 {
-    // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked,
-    // we shouldn't call such things as p_psAlloc/p_psFree here.
-
-    if (m == NULL)
-    {
-        psError(funcName,"Memory Corruption: NULL memory block found.");
-        return(1);
-    }
-
-    if (!ALIGNED(m))
-    {
-        psError(funcName, "psMemCheckCorruption: non-aligned memory block");
-        return(1);
-    }
-
-    if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC)
-    {
-        psError(funcName, "psMemCheckCorruption: memory block %ld is corrupted", m->id);
-        return(1);
-    }
-
-    return(0);
+  // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked,
+  // we shouldn't call such things as p_psAlloc/p_psFree here.
+
+  if (m == NULL)
+    {
+      psError(funcName,"Memory Corruption: NULL memory block found.");
+      return(1);
+    }
+
+  if (!ALIGNED(m))
+    {
+      psError(funcName, "psMemCheckCorruption: non-aligned memory block");
+      return(1);
+    }
+
+  if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC)
+    {
+      psError(funcName, "psMemCheckCorruption: memory block %ld is corrupted", m->id);
+      return(1);
+    }
+
+  return(0);
 }
 
 int psMemCheckCorruption(int abort_on_error)
 {
-    int nbad = 0;                       // number of bad blocks
-
-    // get exclusive access to the memBlock list to avoid it changing on us while we use it.
-    pthread_mutex_lock(&memBlockListMutex);
-
-    for (psMemBlock* iter=lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock)
-    {
-        if (checkMemBlock(iter, __func__))
-        {
-            nbad++;
-
-            memProblemCallback(iter, __func__, __LINE__);
-
-            if (abort_on_error)
+  int nbad = 0;                       // number of bad blocks
+
+  // get exclusive access to the memBlock list to avoid it changing on us while we use it.
+  pthread_mutex_lock(&memBlockListMutex);
+
+  for (psMemBlock* iter=lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock)
+    {
+      if (checkMemBlock(iter, __func__))
+        {
+          nbad++;
+
+          memProblemCallback(iter, __func__, __LINE__);
+
+          if (abort_on_error)
             {
-                // release the lock on the memblock list
-                pthread_mutex_unlock(&memBlockListMutex);
-                psAbort(__func__, "Detected memory corruption");
-                return nbad;
-            }
-        }
-    }
-
-    // release the lock on the memblock list
-    pthread_mutex_unlock(&memBlockListMutex);
-    return nbad;
+              // release the lock on the memblock list
+              pthread_mutex_unlock(&memBlockListMutex);
+              psAbort(__func__, "Detected memory corruption");
+              return nbad;
+            }
+        }
+    }
+
+  // release the lock on the memblock list
+  pthread_mutex_unlock(&memBlockListMutex);
+  return nbad;
 }
 
 void *p_psAlloc(size_t size, const char *file, int lineno)
 {
-    psMemBlock *ptr = malloc(sizeof(psMemBlock) + size);
-
-    if (ptr == NULL)
-    {
-        ptr = memExhaustedCallback(size);
-        if (ptr == NULL)
-        {
-            psAbort(__func__, "Failed to allocate %ld bytes at %s:%d",
-                    size, file, lineno);
-        }
-    }
-
-    *(unsigned long*)&ptr->id = ++memid;
-    ptr->file = file;
-    *(unsigned int*)&ptr->lineno = lineno;
-    ptr->startblock = P_PS_MEMMAGIC;
-    ptr->endblock = P_PS_MEMMAGIC;
-    ptr->refCounter = 1;                // one user so far
-
-    // need exclusive access of the memory block list now...
-    pthread_mutex_lock(&memBlockListMutex);
-
-    // insert the new block to the front of the memBlock linked-list
-    ptr->previousBlock = NULL;
-    ptr->nextBlock = lastMemBlockAllocated;
-    if (ptr->nextBlock != NULL)
-    {
-        ptr->nextBlock->previousBlock = ptr;
-    }
-    lastMemBlockAllocated = ptr;
-
-    pthread_mutex_unlock(&memBlockListMutex);
-
-    //  Did the user ask to be informed about this allocation?
-    if (ptr->id == p_psMemAllocateID)
-    {
-        p_psMemAllocateID += memAllocateCallback(ptr);
-    }
-
-    // And return the user the memory that they allocated
-    return ptr + 1;   // user memory
+  psMemBlock *ptr = malloc(sizeof(psMemBlock) + size);
+
+  if (ptr == NULL)
+    {
+      ptr = memExhaustedCallback(size);
+      if (ptr == NULL)
+        {
+          psAbort(__func__, "Failed to allocate %ld bytes at %s:%d",
+                  size, file, lineno);
+        }
+    }
+
+  *(unsigned long*)&ptr->id = ++memid;
+  ptr->file = file;
+  *(unsigned int*)&ptr->lineno = lineno;
+  ptr->startblock = P_PS_MEMMAGIC;
+  ptr->endblock = P_PS_MEMMAGIC;
+  ptr->refCounter = 1;                // one user so far
+
+  // need exclusive access of the memory block list now...
+  pthread_mutex_lock(&memBlockListMutex);
+
+  // insert the new block to the front of the memBlock linked-list
+  ptr->previousBlock = NULL;
+  ptr->nextBlock = lastMemBlockAllocated;
+  if (ptr->nextBlock != NULL)
+    {
+      ptr->nextBlock->previousBlock = ptr;
+    }
+  lastMemBlockAllocated = ptr;
+
+  pthread_mutex_unlock(&memBlockListMutex);
+
+  //  Did the user ask to be informed about this allocation?
+  if (ptr->id == p_psMemAllocateID)
+    {
+      p_psMemAllocateID += memAllocateCallback(ptr);
+    }
+
+  // And return the user the memory that they allocated
+  return ptr + 1;   // user memory
 }
 
 void *p_psRealloc(void *vptr, size_t size, const char *file, int lineno)
 {
-    if (vptr == NULL)
-    {
-        return p_psAlloc(size, file, lineno);
-    }
-    else
-    {
-        psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-        pthread_mutex_lock(&memBlockListMutex);
-
-        ptr = (psMemBlock*)realloc(ptr, sizeof(psMemBlock) + size);
-
-        // the block location may have changed, so fix the linked list addresses.
-        if (ptr->nextBlock != NULL)
-        {
-            ptr->nextBlock->previousBlock = ptr;
-        }
-        if (ptr->previousBlock != NULL)
-        {
-            ptr->previousBlock->nextBlock = ptr;
-        }
-
-        pthread_mutex_unlock(&memBlockListMutex);
-
-        return ptr + 1;   // usr memory
+  if (vptr == NULL)
+    {
+      return p_psAlloc(size, file, lineno);
+    }
+  else
+    {
+      psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
+
+      pthread_mutex_lock(&memBlockListMutex);
+
+      ptr = (psMemBlock*)realloc(ptr, sizeof(psMemBlock) + size);
+
+      // the block location may have changed, so fix the linked list addresses.
+      if (ptr->nextBlock != NULL)
+        {
+          ptr->nextBlock->previousBlock = ptr;
+        }
+      if (ptr->previousBlock != NULL)
+        {
+          ptr->previousBlock->nextBlock = ptr;
+        }
+
+      pthread_mutex_unlock(&memBlockListMutex);
+
+      return ptr + 1;   // usr memory
     }
 }
@@ -332,51 +332,51 @@
 void p_psFree(void *vptr, const char *file, int lineno)
 {
-    if (vptr == NULL)
-    {
-        return;
-    }
-
-    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-    // Did the user ask to be informed about this deallocation?
-    if (ptr->id == p_psMemFreeID)
-    {
-        p_psMemFreeID += memFreeCallback(ptr);
-    }
-
-    if (checkMemBlock(ptr, "psFree") != 0)
-    {
-        memProblemCallback(ptr, file, lineno); // we may not own this block; don't free it
-    }
-    else
-    {
-        if (ptr->refCounter > 1)
-        {
-            psError(__func__,"The buffer being freed is referenced elsewhere. "
-                    "Buffer's reference count was decremented instead.");
-            ptr->refCounter--;
-            memProblemCallback(ptr, file, lineno);
-        }
-        else
-        {
-
-            // cut the memBlock out of the memBlock list
-            pthread_mutex_lock(&memBlockListMutex);
-            if (ptr->nextBlock != NULL)
+  if (vptr == NULL)
+    {
+      return;
+    }
+
+  psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
+
+  // Did the user ask to be informed about this deallocation?
+  if (ptr->id == p_psMemFreeID)
+    {
+      p_psMemFreeID += memFreeCallback(ptr);
+    }
+
+  if (checkMemBlock(ptr, "psFree") != 0)
+    {
+      memProblemCallback(ptr, file, lineno); // we may not own this block; don't free it
+    }
+  else
+    {
+      if (ptr->refCounter > 1)
+        {
+          psError(__func__,"The buffer being freed is referenced elsewhere. "
+                  "Buffer's reference count was decremented instead.");
+          ptr->refCounter--;
+          memProblemCallback(ptr, file, lineno);
+        }
+      else
+        {
+
+          // cut the memBlock out of the memBlock list
+          pthread_mutex_lock(&memBlockListMutex);
+          if (ptr->nextBlock != NULL)
             {
-                ptr->nextBlock->previousBlock = ptr->previousBlock;
-            }
-            if (ptr->previousBlock != NULL)
+              ptr->nextBlock->previousBlock = ptr->previousBlock;
+            }
+          if (ptr->previousBlock != NULL)
             {
-                ptr->previousBlock->nextBlock = ptr->nextBlock;
-            }
-            if (lastMemBlockAllocated == ptr)
+              ptr->previousBlock->nextBlock = ptr->nextBlock;
+            }
+          if (lastMemBlockAllocated == ptr)
             {
-                lastMemBlockAllocated = ptr->nextBlock;
-            }
-
-            pthread_mutex_unlock(&memBlockListMutex);
-
-            free(ptr);
+              lastMemBlockAllocated = ptr->nextBlock;
+            }
+
+          pthread_mutex_unlock(&memBlockListMutex);
+
+          free(ptr);
         }
     }
@@ -387,59 +387,59 @@
  */
 int psMemCheckLeaks(
-    int id0,                            // don't list blocks with id < id0
-    psMemBlock ***arr,                  // pointer to array of pointers to leaked blocks, or NULL
-    FILE *fd)                           // print list of leaks to fd (or NULL)
-{
-    int nleak = 0;
-    int j = 0;
-
-    pthread_mutex_lock(&memBlockListMutex);
-
-    for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock)
-    {
-        if ( (iter->refCounter > 0) && (iter->id >= id0) )
-        {
-            nleak++;
-
-            if (fd != NULL)
+  int id0,                            // don't list blocks with id < id0
+  psMemBlock ***arr,                  // pointer to array of pointers to leaked blocks, or NULL
+  FILE *fd)                           // print list of leaks to fd (or NULL)
+{
+  int nleak = 0;
+  int j = 0;
+
+  pthread_mutex_lock(&memBlockListMutex);
+
+  for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock)
+    {
+      if ( (iter->refCounter > 0) && (iter->id >= id0) )
+        {
+          nleak++;
+
+          if (fd != NULL)
             {
-                if (nleak == 1)
+              if (nleak == 1)
                 {
-                    fprintf(fd, "   %20s:line ID\n", "file");
+                  fprintf(fd, "   %20s:line ID\n", "file");
                 }
 
-                fprintf(fd, "   %20s:%-4d %ld\n", iter->file, iter->lineno, iter->id);
-            }
-        }
-    }
-
-    pthread_mutex_unlock(&memBlockListMutex);
-
-    if (nleak == 0 || arr == NULL)
-    {
-        return nleak;
-    }
-
-    p_psFree(*arr,__FILE__, __LINE__);  // Don't generate a memory leak!
-
-    *arr = p_psAlloc(nleak*sizeof(psMemBlock), __FILE__, __LINE__);
-
-    pthread_mutex_lock(&memBlockListMutex);
-
-    for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock)
-    {
-        if ( (iter->refCounter > 0) && (iter->id >= id0) )
-        {
-            (*arr)[j++] = iter;
-            if (j == nleak)
+              fprintf(fd, "   %20s:%-4d %ld\n", iter->file, iter->lineno, iter->id);
+            }
+        }
+    }
+
+  pthread_mutex_unlock(&memBlockListMutex);
+
+  if (nleak == 0 || arr == NULL)
+    {
+      return nleak;
+    }
+
+  p_psFree(*arr,__FILE__, __LINE__);  // Don't generate a memory leak!
+
+  *arr = p_psAlloc(nleak*sizeof(psMemBlock), __FILE__, __LINE__);
+
+  pthread_mutex_lock(&memBlockListMutex);
+
+  for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock)
+    {
+      if ( (iter->refCounter > 0) && (iter->id >= id0) )
+        {
+          (*arr)[j++] = iter;
+          if (j == nleak)
             { // found them all
-                break;
-            }
-        }
-    }
-
-    pthread_mutex_unlock(&memBlockListMutex);
-
-    return nleak;
+              break;
+            }
+        }
+    }
+
+  pthread_mutex_unlock(&memBlockListMutex);
+
+  return nleak;
 }
 
@@ -449,49 +449,49 @@
 int psMemGetRefCounter(void *vptr) // return refCounter
 {
-    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__) != 0)
-    {
-        memProblemCallback(ptr, __func__, __LINE__);
-    }
-
-    return ptr->refCounter;
+  psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
+
+  if (checkMemBlock(ptr, __func__) != 0)
+    {
+      memProblemCallback(ptr, __func__, __LINE__);
+    }
+
+  return ptr->refCounter;
 }
 
 void *psMemIncrRefCounter(void *vptr) // increment and return refCounter
 {
-    if (vptr == NULL)
-    {
-        return vptr;
-    }
-
-    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__))
-    {
-        memProblemCallback(ptr, __func__, __LINE__);
-    }
-
-    ptr->refCounter++;
-
-    return vptr;
+  if (vptr == NULL)
+    {
+      return vptr;
+    }
+
+  psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
+
+  if (checkMemBlock(ptr, __func__))
+    {
+      memProblemCallback(ptr, __func__, __LINE__);
+    }
+
+  ptr->refCounter++;
+
+  return vptr;
 }
 
 void *psMemDecrRefCounter(void *vptr) // decrement and return refCounter
 {
-    if (vptr == NULL)
-    {
-        return vptr;
-    }
-
-    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__))
-    {
-        memProblemCallback(ptr, __func__, __LINE__);
-    }
-
-    ptr->refCounter--;
-
-    return vptr;
-}
+  if (vptr == NULL)
+    {
+      return vptr;
+    }
+
+  psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
+
+  if (checkMemBlock(ptr, __func__))
+    {
+      memProblemCallback(ptr, __func__, __LINE__);
+    }
+
+  ptr->refCounter--;
+
+  return vptr;
+}
