Index: trunk/psModules/src/objects/pmPSFtry.c
===================================================================
--- trunk/psModules/src/objects/pmPSFtry.c	(revision 8882)
+++ trunk/psModules/src/objects/pmPSFtry.c	(revision 9316)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-09-22 12:24:38 $
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-05 23:40:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -216,13 +216,22 @@
     stats->clipIter = 3;
     // linear clipped fit of ApResid to r2rflux
-    psVectorClipFitPolynomial1D (psfTry->psf->ChiTrend, stats, mask, 1, chisq, NULL, flux);
+    psfTry->psf->ChiTrend =
+        psVectorClipFitPolynomial1D(psfTry->psf->ChiTrend, stats, mask, 1, chisq, NULL, flux);
+    psLogMsg ("pmPSFtry", 4, "chisq vs flux fit: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
+
+    psFree (flux);
+    psFree (stats);
+    psFree (mask);
+    psFree (chisq);
+
+    if (psfTry->psf->ChiTrend == NULL) {
+        psError(PS_ERR_UNKNOWN, false, "Failed to fit psf->ChiTrend");
+        psFree(psfTry);
+        return NULL;
+    }
+
     for (int i = 0; i < psfTry->psf->ChiTrend->nX + 1; i++) {
         psLogMsg ("pmPSFtry", 4, "chisq vs flux fit term %d: %f +/- %f\n", i, psfTry->psf->ChiTrend->coeff[i]*pow(10000, i), psfTry->psf->ChiTrend->coeffErr[i]*pow(10000,i));
     }
-    psLogMsg ("pmPSFtry", 4, "chisq vs flux fit: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
-    psFree (stats);
-    psFree (flux);
-    psFree (mask);
-    psFree (chisq);
 
     // XXX this function wants aperture radius for pmSourcePhotometry
