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
