Index: trunk/psLib/src/math/psStats.c
===================================================================
--- trunk/psLib/src/math/psStats.c	(revision 27313)
+++ trunk/psLib/src/math/psStats.c	(revision 27334)
@@ -751,11 +751,11 @@
         psTrace(TRACE, 6, "-------------------- Iterating on Bin size.  Iteration number %d --------------------\n", iterate);
 
-	if (iterate >= PS_ROBUST_MAX_ITERATIONS) {
-	  // This occurs when a large number of the values are identical --- a bin size cannot be found
-	  // that will spread out the distribution.  Therefore, set what we can, and fall over
-	  // gracefully.
-	  COUNT_WARNING(10, 100, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS);
-	  goto escape;
-	}
+        if (iterate >= PS_ROBUST_MAX_ITERATIONS) {
+          // This occurs when a large number of the values are identical --- a bin size cannot be found
+          // that will spread out the distribution.  Therefore, set what we can, and fall over
+          // gracefully.
+          COUNT_WARNING(10, 100, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS);
+          goto escape;
+        }
 
         // Get the minimum and maximum values
@@ -823,42 +823,42 @@
         }
 
-	// perversity check: if most of the values land in a single bin, then we probably
-	// have a perverse case (eg, small number of points at extremely large / small
-	// values; nearly bi-modal distribution).  if so, keep only points within 5? 10?
-	// bins of that excess bin:
-	int nMaxBin = 0;
-	int iMaxBin = 0;
+        // perversity check: if most of the values land in a single bin, then we probably
+        // have a perverse case (eg, small number of points at extremely large / small
+        // values; nearly bi-modal distribution).  if so, keep only points within 5? 10?
+        // bins of that excess bin:
+        int nMaxBin = 0;
+        int iMaxBin = 0;
         for (long i = 1; i < histogram->nums->n; i++) {
-	    if (histogram->nums->data.F32[i] > nMaxBin) {
-		nMaxBin = histogram->nums->data.F32[i];
-		iMaxBin = i;
-	    }
-        }
-	if (nMaxBin > numValid / 2) {
-	    float minKeep = histogram->bounds->data.F32[iMaxBin] - 10*binSize;
-	    float maxKeep = histogram->bounds->data.F32[iMaxBin + 1] + 10*binSize;
-	    int nInvalid = 0;
-	    for (long i = 0; i < myVector->n; i++) {
-		// skip the already-masked values
-		if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) continue;
-		bool invalid = false;
-		invalid |= (myVector->data.F32[i] <= minKeep);
-		invalid |= (myVector->data.F32[i] >= maxKeep);
-		invalid |= (!isfinite(myVector->data.F32[i]));
-		if (!invalid) continue;
-		mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = maskVal;
-		nInvalid ++;
-            }
-
-	    if (nInvalid) {
-	      psTrace(TRACE, 6, "data is concentrated in a single bin, masking %d extreme outliers and retrying\n", nInvalid);
-	      psFree(histogram);
-	      psFree(cumulative);
-	      histogram = NULL;
-	      cumulative = NULL;
-	      continue;
-	    }
-	    // if we did not mask anything, give up.
-	}
+            if (histogram->nums->data.F32[i] > nMaxBin) {
+                nMaxBin = histogram->nums->data.F32[i];
+                iMaxBin = i;
+            }
+        }
+        if (nMaxBin > numValid / 2) {
+            float minKeep = histogram->bounds->data.F32[iMaxBin] - 10*binSize;
+            float maxKeep = histogram->bounds->data.F32[iMaxBin + 1] + 10*binSize;
+            int nInvalid = 0;
+            for (long i = 0; i < myVector->n; i++) {
+                // skip the already-masked values
+                if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) continue;
+                bool invalid = false;
+                invalid |= (myVector->data.F32[i] <= minKeep);
+                invalid |= (myVector->data.F32[i] >= maxKeep);
+                invalid |= (!isfinite(myVector->data.F32[i]));
+                if (!invalid) continue;
+                mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = maskVal;
+                nInvalid ++;
+            }
+
+            if (nInvalid) {
+              psTrace(TRACE, 6, "data is concentrated in a single bin, masking %d extreme outliers and retrying\n", nInvalid);
+              psFree(histogram);
+              psFree(cumulative);
+              histogram = NULL;
+              cumulative = NULL;
+              continue;
+            }
+            // if we did not mask anything, give up.
+        }
 
         // ADD step 1: Convert the specific histogram to a cumulative histogram
@@ -1873,4 +1873,5 @@
             COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
             psFree(statsMinMax);
+            psFree(histogram);
             goto escape;
         }
@@ -1942,5 +1943,5 @@
 
             if (!status) {
-	        psErrorClear();
+                psErrorClear();
                 COUNT_WARNING(10, 100, "Failed to fit a gaussian to the robust histogram.\n");
                 psFree(poly);
@@ -2032,5 +2033,5 @@
 
             if (!status) {
-	        psErrorClear();
+                psErrorClear();
                 COUNT_WARNING(10, 100, "Failed to fit a gaussian to the robust histogram.\n");
                 psFree(poly);
