Index: trunk/psLib/src/sysUtils/psMemory.c
===================================================================
--- trunk/psLib/src/sysUtils/psMemory.c	(revision 451)
+++ trunk/psLib/src/sysUtils/psMemory.c	(revision 452)
@@ -8,6 +8,6 @@
  *  @author Robert Lupton, Princeton University
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-04-19 20:14:04 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-04-19 20:19:22 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -49,8 +49,8 @@
 
     if (func != NULL) {
-	    memExhaustedCallback = func;
-	} else {
-	    memExhaustedCallback = memExhaustedCallbackDefault;
-	}
+        memExhaustedCallback = func;
+    } else {
+        memExhaustedCallback = memExhaustedCallbackDefault;
+    }
 
     return old;
@@ -58,19 +58,19 @@
 
 static void memProblemCallbackDefault(const psMemBlock *ptr,
-                          const char *file, int lineno)
+                                      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) {
+    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);
     }
@@ -83,8 +83,8 @@
 
     if (func != NULL) {
-	    memProblemCallback = func;
-	} else {
-	    memProblemCallback = memProblemCallbackDefault;
-	}
+        memProblemCallback = func;
+    } else {
+        memProblemCallback = memProblemCallbackDefault;
+    }
 
     return old;
@@ -145,8 +145,8 @@
 
     if (func != NULL) {
-	    memAllocateCallback =  func;
-	} else {
-	    memAllocateCallback = memAllocateCallbackDefault;
-	}
+        memAllocateCallback =  func;
+    } else {
+        memAllocateCallback = memAllocateCallbackDefault;
+    }
 
     return old;
@@ -158,8 +158,8 @@
 
     if (func != NULL) {
-	    memFreeCallback = func;
-	} else {
-	    memFreeCallback = memFreeCallbackDefault;
-	}
+        memFreeCallback = func;
+    } else {
+        memFreeCallback = memFreeCallbackDefault;
+    }
 
     return old;
@@ -185,5 +185,5 @@
 static int
 checkMemBlock(const psMemBlock *m,
-             const char* funcName)
+              const char* funcName)
 {
     // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked,
@@ -212,25 +212,24 @@
     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)
-{
+    // 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);
+            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;
 }
@@ -254,19 +253,19 @@
     *(unsigned int*)&ptr->lineno = lineno;
     ptr->startblock = P_PS_MEMMAGIC;
-	ptr->endblock = 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);
+    // 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?
@@ -275,5 +274,5 @@
     }
 
-	// And return the user the memory that they allocated
+    // And return the user the memory that they allocated
     return ptr + 1;   // user memory
 }
@@ -286,19 +285,19 @@
         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
+        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
     }
 }
@@ -312,5 +311,5 @@
     psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
 
-	// Did the user ask to be informed about this deallocation?
+    // Did the user ask to be informed about this deallocation?
     if (ptr->id == p_psMemFreeID) {
         p_psMemFreeID += memFreeCallback(ptr);
@@ -321,26 +320,26 @@
     } else {
         if (ptr->refCounter > 1) {
-		    psError(__func__,"The buffer being freed is referenced elsewhere. "
-			        "Buffer's reference count was decremented instead.");
+            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);
-		}
+            // 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);
+        }
     }
 }
@@ -356,25 +355,27 @@
 {
     int nleak = 0;
-	int j = 0;
-
-	pthread_mutex_lock(&memBlockListMutex);
-
-    for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock) {
+    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) {
+            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;
     }
@@ -384,12 +385,13 @@
     *arr = p_psAlloc(nleak*sizeof(psMemBlock), __FILE__, __LINE__);
 
-	pthread_mutex_lock(&memBlockListMutex);
-
-    for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock) {
+    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;
-			}
+            (*arr)[j++] = iter;
+            if (j == nleak) { // found them all
+                break;
+            }
         }
     }
@@ -418,5 +420,6 @@
 void *psMemIncrRefCounter(void *vptr) // increment and return refCounter
 {
-    if (vptr == NULL) {
+    if (vptr == NULL)
+    {
         return vptr;
     }
@@ -424,5 +427,6 @@
     psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
 
-    if (checkMemBlock(ptr, __func__)) {
+    if (checkMemBlock(ptr, __func__))
+    {
         memProblemCallback(ptr, __func__, __LINE__);
     }
@@ -435,5 +439,6 @@
 void *psMemDecrRefCounter(void *vptr) // decrement and return refCounter
 {
-    if (vptr == NULL) {
+    if (vptr == NULL)
+    {
         return vptr;
     }
@@ -441,5 +446,6 @@
     psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
 
-    if (checkMemBlock(ptr, __func__)) {
+    if (checkMemBlock(ptr, __func__))
+    {
         memProblemCallback(ptr, __func__, __LINE__);
     }
