Index: trunk/psphot/src/psphotEnsemblePSF.c
===================================================================
--- trunk/psphot/src/psphotEnsemblePSF.c	(revision 6056)
+++ trunk/psphot/src/psphotEnsemblePSF.c	(revision 6379)
@@ -1,4 +1,6 @@
 # include "psphot.h"
 
+// 2006.02.07 : no leaks!
+// fit all reasonable sources with the linear PSF model
 bool psphotEnsemblePSF (pmReadout *readout, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky) { 
 
@@ -6,4 +8,5 @@
     float x;
     float y;
+    float f;
 
     psTimerStart ("psphot");
@@ -28,5 +31,5 @@
     bool UseAnalysisRegion = false;
     psRegion AnalysisRegion = {0, 0, 0, 0};
-    char *region = psMetadataLookupPtr (&status, config, "ANALYSIS_REGION");
+    char *region = psMetadataLookupStr (&status, config, "ANALYSIS_REGION");
     if (status) {
 	UseAnalysisRegion = true;
@@ -126,9 +129,8 @@
 	index->data.U32[models->n] = i;
 	psArrayAdd (models, 100, otSource);
+	psFree (otSource);
     }
     psLogMsg ("psphot.emsemble", 4, "built models: %f (%d objects)\n", psTimerMark ("psphot"), sources->n);
     
-    float f;
-
     // fill out the sparse matrix
     psSparse *sparse = psSparseAlloc (models->n, 100);
@@ -173,5 +175,6 @@
 	pmSource *Mi = models->data[i];
 
-	Fi->modelPSF = Mi->modelPSF;
+	// need to increment counter so we can free models here and sources above
+	Fi->modelPSF = psMemCopy (Mi->modelPSF);
 
 	// assign linearly-fitted normalization
@@ -183,6 +186,8 @@
 	Fi->mode |= PM_SOURCE_TEMPSUB;
     }
-
-    // XXX EAM : need to free up many things here
+    psFree (index);
+    psFree (sparse);
+    psFree (models);
+    psFree (norm);
 
     psLogMsg ("psphot.emsemble", 3, "measure ensemble of PSFs: %f sec\n", psTimerMark ("psphot"));
