Index: /tags/ipp-20100823/psLib/src/math/psMinimizeLMM.c
===================================================================
--- /tags/ipp-20100823/psLib/src/math/psMinimizeLMM.c	(revision 29338)
+++ /tags/ipp-20100823/psLib/src/math/psMinimizeLMM.c	(revision 29339)
@@ -325,7 +325,7 @@
         chisq += PS_SQR(delta) * dy->data.F32[i];
 
-        if (isnan(dy->data.F32[i])) return NAN;
-        if (isnan(delta)) return NAN;
-        if (isnan(chisq)) return NAN;
+        if (isnan(dy->data.F32[i])) goto escape;
+        if (isnan(delta)) goto escape;
+        if (isnan(chisq)) goto escape;
 
         // we track alpha,beta and params,deriv separately
@@ -354,4 +354,8 @@
     psFree(deriv);
     return(chisq);
+
+escape:
+    psFree(deriv);
+    return NAN;
 }
 
@@ -448,4 +452,9 @@
     if (isnan(min->value)) {
         min->iter = min->maxIter;
+	psFree(alpha);
+	psFree(Alpha);
+	psFree(beta);
+	psFree(Beta);
+	psFree(Params);
         return(false);
     }
Index: /tags/ipp-20100823/psphot/src/psphotSourceFits.c
===================================================================
--- /tags/ipp-20100823/psphot/src/psphotSourceFits.c	(revision 29338)
+++ /tags/ipp-20100823/psphot/src/psphotSourceFits.c	(revision 29339)
@@ -549,6 +549,7 @@
 	// for the test fits, use a somewhat smaller radius
 	psphotSetRadiusFootprint(&model->fitRadius, readout, source, markVal, 0.5);
-
+	
     	if (!psphotFitSersicIndexPCM (pcm, readout, source, fitOptions, maskVal, markVal, psfSize)) {
+	    psFree(pcm);
 	    model->flags |= PM_MODEL_STATUS_BADARGS;
 	    return model;
