Index: /trunk/psphot/src/psphotApResid.c
===================================================================
--- /trunk/psphot/src/psphotApResid.c	(revision 14951)
+++ /trunk/psphot/src/psphotApResid.c	(revision 14952)
@@ -189,5 +189,10 @@
     psFree (xPos);
     psFree (yPos);
+
     psFree (apResid);
+    psFree (apResidFit);
+    psFree (apResidRes);
+
+    psFree (dMagSys);
     psFree (dMag);
 
@@ -269,8 +274,4 @@
     int Nx, Ny;
 	
-    psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
-    stats->min = 2.0;
-    stats->max = 3.0;
-
     if (readout->image->numCols > readout->image->numRows) {
 	Nx = scale;
@@ -285,4 +286,9 @@
     }
 
+    // XXX stats structure for use by ApTrend : make parameters user setable
+    psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
+    stats->min = 2.0;
+    stats->max = 3.0;
+
     // measure Trend2D for the current spatial scale
     psFree (psf->ApTrend);
