Index: trunk/psphot/src/psphotBasicDeblend.c
===================================================================
--- trunk/psphot/src/psphotBasicDeblend.c	(revision 6311)
+++ trunk/psphot/src/psphotBasicDeblend.c	(revision 6319)
@@ -1,4 +1,6 @@
 # include "psphot.h"
 
+// 2006.02.02 : no leaks? (creates source->blend entries)
+// XXX if I free sources, I still have 54 leaks?
 bool psphotBasicDeblend (psArray *sources, psMetadata *config, psStats *sky) { 
 
@@ -109,4 +111,5 @@
 		}
 	    }  
+	    psFree (contour);
 	}
     }
@@ -116,4 +119,8 @@
     if (!strcasecmp (breakPt, "DEBLEND")) exit (0);
 
+    psFree (SN);
+    psFree (index);
+    psFree (overlap);
+    
     return true;
 }
Index: trunk/psphot/src/psphotImageBackground.c
===================================================================
--- trunk/psphot/src/psphotImageBackground.c	(revision 6311)
+++ trunk/psphot/src/psphotImageBackground.c	(revision 6319)
@@ -1,4 +1,5 @@
 # include "psphot.h"
 
+// 2006.02.02 : no leaks
 psPolynomial2D *psphotImageBackground (pmReadout *readout, psMetadata *config, psStats *sky) 
 { 
@@ -61,4 +62,9 @@
     sky->sampleMean = 0.0;
 
+    psFree (x);
+    psFree (y);
+    psFree (z);
+    psFree (rnd);  // XXX should this be made available at a higher level?
+
     psLogMsg ("psphot", 3, "fit background model: %f sec\n", psTimerMark ("psphot"));
     return (skyModel);
Index: trunk/psphot/src/psphotReadout.c
===================================================================
--- trunk/psphot/src/psphotReadout.c	(revision 6311)
+++ trunk/psphot/src/psphotReadout.c	(revision 6319)
@@ -1,3 +1,10 @@
 # include "psphot.h"
+
+# define MEM_0 psMemId ID = psMemGetId ();
+# define MEM_1(A) \
+    psTimerStop ();\
+    if (A != NULL) { psFree (A); } \
+    fprintf (stderr, "found %d leaks\n", psMemCheckLeaks (ID, NULL, NULL, false));\
+    exit (1);
 
 bool psphotReadout (pmReadout *readout, psMetadata *config) {
@@ -8,4 +15,5 @@
     psStats     *sky     = NULL;
     bool         status;
+    psPolynomial2D *model = NULL;
 
     psphotSaveImage (NULL, readout->mask, "mask.fits");
@@ -18,5 +26,5 @@
     // generate a background model (currently, 2D polynomial)
     // XXX this should be available to be re-added to the original image
-    psphotImageBackground (readout, config, sky);
+    model = psphotImageBackground (readout, config, sky);
 
     // find the peaks in the image
@@ -33,5 +41,7 @@
 
     // use bright stellar objects to measure PSF
+    MEM_0;
     psf = psphotChoosePSF (config, sources, sky);
+    MEM_1(psf);
 
     // XXX change FITMODE to a string
