Index: trunk/psLib/src/math/psPolynomialUtils.c
===================================================================
--- trunk/psLib/src/math/psPolynomialUtils.c	(revision 10607)
+++ trunk/psLib/src/math/psPolynomialUtils.c	(revision 10848)
@@ -13,5 +13,5 @@
 #include "psPolynomialUtils.h"
 
-psPolynomial4D *psVectorChiClipFitPolynomial4D(
+bool psVectorChiClipFitPolynomial4D(
     psPolynomial4D *poly,
     psStats *stats,
@@ -75,11 +75,24 @@
         int Nkeep = 0;
 
-        poly = psVectorFitPolynomial4D (poly, mask, maskValue, f, fErr, x, y, z, t);
+        if (!psVectorFitPolynomial4D (poly, mask, maskValue, f, fErr, x, y, z, t)) {
+            psError(PS_ERR_UNKNOWN, true, "Could not fit a polynomial to the data.  Returning NULL.\n");
+            psFree (resid);
+            return false;
+        }
+
         fit = psPolynomial4DEvalVector (poly, x, y, z, t);
+        if (fit == NULL) {
+            psError(PS_ERR_UNKNOWN, false, "Could not call psPolynomial4DEvalVector().  Returning NULL.\n");
+            psFree(resid)
+            return false;
+        }
+
         resid = (psVector *) psBinaryOp (resid, (void *) f, "-", (void *) fit);
 
         if (!psVectorStats (stats, resid, NULL, mask, maskValue)) {
             psError(PS_ERR_UNKNOWN, false, "failed to measure vector stats");
-            return NULL;
+            psFree (fit);
+            psFree (resid);
+            return false;
         }
         psTrace (__func__, 5, "resid stats: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
@@ -108,7 +121,5 @@
         }
 
-        psTrace (__func__, 4, "keeping %d of %ld pts for fit\n",
-                 Nkeep, x->n);
-
+        psTrace (__func__, 4, "keeping %d of %ld pts for fit\n", Nkeep, x->n);
         stats->clippedNvalues = Nkeep;
         psFree (fit);
@@ -117,9 +128,5 @@
     psFree (resid);
 
-    if (poly == NULL) {
-        psError(PS_ERR_UNKNOWN, true, "Could not fit a polynomial to the data.  Returning NULL.\n");
-        return(NULL);
-    }
-    return(poly);
+    return true;
 }
 
