Index: branches/eam_branches/ipp-20150326/psastro/src/psastroGalaxyShapeErrors.c
===================================================================
--- branches/eam_branches/ipp-20150326/psastro/src/psastroGalaxyShapeErrors.c	(revision 38022)
+++ branches/eam_branches/ipp-20150326/psastro/src/psastroGalaxyShapeErrors.c	(revision 38025)
@@ -69,4 +69,13 @@
             float *dPAR = model->dparams->data.F32;
 
+	    if (!(isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXY]) && isfinite(PAR[PM_PAR_SYY]))) {
+	      // set a mask bit
+	      continue;
+	    }
+	    if (!(isfinite(dPAR[PM_PAR_SXX]) && isfinite(dPAR[PM_PAR_SXY]) && isfinite(dPAR[PM_PAR_SYY]))) {
+	      // set a (different) mask bit
+	      continue;
+	    }
+
 	    // psphot writes out dPAR, but PAR is writen as MAJOR,MINOR,THETA but transformed
 	    // to PAR[SXX,SXY,SYY] when the cmf is read.  here we use a monte carlo to generate
@@ -85,4 +94,8 @@
 		float Sxy = PAR[PM_PAR_SXY] + dPAR[PM_PAR_SXY]*psRandomGaussian(rng);
 		float Syy = PAR[PM_PAR_SYY] + dPAR[PM_PAR_SYY]*psRandomGaussian(rng);
+		if (!(isfinite(Sxx) && isfinite(Sxy) && isfinite(Syy))) {
+		  continue;
+		}
+
 		pmModelParamsToAxes (&axes, Sxx, Sxy, Syy, useReff);
 		if (!(isfinite(axes.major) && isfinite(axes.minor) && isfinite(axes.theta))) continue;
@@ -111,6 +124,10 @@
     }
     psFree (rng);
+    psFree (stats);
+    psFree (majorValues);
+    psFree (minorValues);
+    psFree (thetaValues);
 
-    psLogMsg ("psastro.galaxy", PS_LOG_INFO, "monte carlo shape errors for %d of %d objects: %f sec\n", nObjects, (int) sources->n, psTimerMark ("psphot.choose.psf"));
+    psLogMsg ("psastro.galaxy", PS_LOG_INFO, "monte carlo shape errors for %d of %d objects: %f sec\n", nObjects, (int) sources->n, psTimerMark ("psastro.galaxy.shape.errors"));
     return true;
 }
