Index: trunk/psphot/src/psphotModelBackground.c
===================================================================
--- trunk/psphot/src/psphotModelBackground.c	(revision 16820)
+++ trunk/psphot/src/psphotModelBackground.c	(revision 17568)
@@ -163,27 +163,27 @@
             // XXX don't bother trying if there are no valid pixels...
 
-	    psVector *sample = NULL;
-
-	    // turn on stats tracing in desired cells
-	    # if (0)
-	    psMetadata *plots = psMetadataLookupPtr (&status, recipe, "DIAGNOSTIC.PLOTS");
-	    assert (plots);
-	    
-	    int xPlot = psMetadataLookupS32 (&status, plots, "IMAGE.BACKGROUND.CELL.HISTOGRAM.X");
-	    assert (status);
-	    int yPlot = psMetadataLookupS32 (&status, plots, "IMAGE.BACKGROUND.CELL.HISTOGRAM.Y");
-	    assert (status);
-
-	    bool gotX = (xPlot < 0) || (xPlot == ix);
-	    bool gotY = (yPlot < 0) || (yPlot == iy);
-
-	    if (gotX && gotY) {
-		psTraceSetLevel ("psLib.math.vectorFittedStats_v4", 6);
-		psTraceSetLevel ("psLib.math.vectorRobustStats", 6);
-	    } else {
-		psTraceSetLevel ("psLib.math.vectorFittedStats_v4", 0);
-		psTraceSetLevel ("psLib.math.vectorRobustStats", 0);
-	    }	    
-	    # endif
+            psVector *sample = NULL;
+
+            // turn on stats tracing in desired cells
+            # if (0)
+            psMetadata *plots = psMetadataLookupPtr (&status, recipe, "DIAGNOSTIC.PLOTS");
+            assert (plots);
+
+            int xPlot = psMetadataLookupS32 (&status, plots, "IMAGE.BACKGROUND.CELL.HISTOGRAM.X");
+            assert (status);
+            int yPlot = psMetadataLookupS32 (&status, plots, "IMAGE.BACKGROUND.CELL.HISTOGRAM.Y");
+            assert (status);
+
+            bool gotX = (xPlot < 0) || (xPlot == ix);
+            bool gotY = (yPlot < 0) || (yPlot == iy);
+
+            if (gotX && gotY) {
+                psTraceSetLevel ("psLib.math.vectorFittedStats_v4", 6);
+                psTraceSetLevel ("psLib.math.vectorRobustStats", 6);
+            } else {
+                psTraceSetLevel ("psLib.math.vectorFittedStats_v4", 0);
+                psTraceSetLevel ("psLib.math.vectorRobustStats", 0);
+            }
+            # endif
 
             if (psImageBackground(stats, &sample, subset, submask, maskVal, rng)) {
@@ -195,7 +195,6 @@
                 modelStdevData[iy][ix] = psStatsGetValue(stats, statsOptionWidth);
 
-		// supply sample to plotting routing
-		psphotDiagnosticPlots (config, "IMAGE.BACKGROUND.CELL.HISTOGRAM", ix, iy, modelData[iy][ix], modelStdevData[iy][ix], sample);
-		psFree (sample);
+                // supply sample to plotting routing
+                psphotDiagnosticPlots (config, "IMAGE.BACKGROUND.CELL.HISTOGRAM", ix, iy, modelData[iy][ix], modelStdevData[iy][ix], sample);
             } else {
                 psStatsOptions currentOptions = stats->options;
@@ -210,7 +209,6 @@
                     modelStdevData[iy][ix] = psStatsGetValue(stats, PS_STAT_ROBUST_STDEV);
 
-		    // supply sample to plotting routing
-		    psphotDiagnosticPlots (config, "IMAGE.BACKGROUND.CELL.HISTOGRAM", ix, iy, modelData[iy][ix], modelStdevData[iy][ix], sample);
-		    psFree (sample);
+                    // supply sample to plotting routing
+                    psphotDiagnosticPlots (config, "IMAGE.BACKGROUND.CELL.HISTOGRAM", ix, iy, modelData[iy][ix], modelStdevData[iy][ix], sample);
                 }
                 // drop errors caused by psImageBackground failures
@@ -219,4 +217,5 @@
                 stats->options = currentOptions;
             }
+            psFree(sample);
             modelData[iy][ix] += SKY_BIAS;
             psFree (subset);
@@ -263,8 +262,8 @@
     if (Count == 0) {
         psError (PSPHOT_ERR_DATA, true, "failed to build background image");
-	psFree(stats);
-	psFree(statsDefaults);
-	psFree(binning);
-	psFree(rng);
+        psFree(stats);
+        psFree(statsDefaults);
+        psFree(binning);
+        psFree(rng);
         return false;
     }
