Index: trunk/psphot/src/choose_psf_model.c
===================================================================
--- trunk/psphot/src/choose_psf_model.c	(revision 4630)
+++ trunk/psphot/src/choose_psf_model.c	(revision 4642)
@@ -34,8 +34,11 @@
 	modelName = psMetadataLookupPtr (&status, config, key);
 	tests->data[i] = pmPSF_TestModel (stars, modelName, RADIUS);
+	psFree (modelName);
 
-	sprintf (filename, "metric.%d.dat", i);
-	DumpPSFTestData (tests->data[i], filename);
+	// make this an option:
+	// sprintf (filename, "metric.%d.dat", i);
+	// DumpPSFTestData (tests->data[i], filename);
     }
+    psFree (stars);
 
     // select the best of the test models
@@ -46,5 +49,5 @@
     for (int i = 1; i < Ntest; i++) {
 	test = tests->data[i];
-	int M = test->dApResid;
+	float M = test->dApResid;
 	if (M < bestM) {
 	    bestM = M;
@@ -55,5 +58,8 @@
     modelName = psModelGetType (test->modelType);
     psLogMsg ("psphot.pspsf", 3, "selected psf model %s, ApResid: %f +/- %f\n", modelName, test->ApResid, test->dApResid);
+    psFree (modelName);
 
+    // we are keeping the modelPSF fits from the PSF test, 
+    // but we replace these later on (apply_psf_model)
     // set source->model based on best psf model fit
     for (int i = 0; i < test->sources->n; i++) {
@@ -67,4 +73,10 @@
 	}
     }
-    return (test->psf);
+    pmPSF *psf = test->psf;
+
+    // free unused test models:
+    psFree (test);
+    psFree (stars);
+
+    return (psf);
 }
