Index: trunk/psModules/src/objects/pmSource.c
===================================================================
--- trunk/psModules/src/objects/pmSource.c	(revision 15232)
+++ trunk/psModules/src/objects/pmSource.c	(revision 15562)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-10-06 02:29:47 $
+ *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-11-10 01:09:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -77,8 +77,15 @@
 }
 
+bool psMemCheckSource(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) sourceFree);
+}
+
 /******************************************************************************
 pmSourceAlloc(): Allocate the pmSource structure and initialize its members
 to NULL.
 *****************************************************************************/
+
 pmSource *pmSourceAlloc()
 {
@@ -132,4 +139,7 @@
 pmSource *pmSourceCopy(pmSource *in)
 {
+    if (in == NULL) {
+        return(NULL);
+    }
     // this copy is used to allow multiple fit attempts on the
     // same object.  the pixels, weight, and mask arrays all point to
@@ -139,19 +149,23 @@
 
     // this is actually the same peak as the original, is this the correct way to handle this?
-    source->peak = pmPeakAlloc (in->peak->x, in->peak->y, in->peak->value, in->peak->type);
-    source->peak->xf = in->peak->xf;
-    source->peak->yf = in->peak->yf;
-    source->peak->flux = in->peak->flux;
-    source->peak->SN = in->peak->SN;
+    if (in->peak != NULL) {
+        source->peak = pmPeakAlloc (in->peak->x, in->peak->y, in->peak->value, in->peak->type);
+        source->peak->xf = in->peak->xf;
+        source->peak->yf = in->peak->yf;
+        source->peak->flux = in->peak->flux;
+        source->peak->SN = in->peak->SN;
+    }
 
     // copy the values in the moments structure
-    source->moments  =  pmMomentsAlloc();
-    *source->moments = *in->moments;
+    if (in->moments != NULL) {
+        source->moments  =  pmMomentsAlloc();
+        *source->moments = *in->moments;
+    }
 
     // These images are all views to the parent.
     // We want a new view, but pointing at the same pixels.
-    source->pixels   = psImageCopyView (NULL, in->pixels);
-    source->weight   = psImageCopyView (NULL, in->weight);
-    source->maskView = psImageCopyView (NULL, in->maskView);
+    source->pixels   = psImageCopyView(NULL, in->pixels);
+    source->weight   = psImageCopyView(NULL, in->weight);
+    source->maskView = psImageCopyView(NULL, in->maskView);
 
     // the maskObj is a unique mask array; create a new mask image
@@ -173,4 +187,9 @@
                           psF32 Radius)
 {
+    PS_ASSERT_PTR_NON_NULL(mySource, false);
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+    PS_ASSERT_PTR_NON_NULL(readout->image, false);
+    PS_ASSERT_INT_POSITIVE(Radius, false);
+
     psRegion srcRegion;
 
@@ -200,9 +219,11 @@
                             psF32 Radius)
 {
+    PS_ASSERT_PTR_NON_NULL(mySource, false);
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+    PS_ASSERT_PTR_NON_NULL(readout->image, false);
+    PS_ASSERT_INT_POSITIVE(Radius, false);
+
     bool extend;
     psRegion newRegion;
-
-    if (Radius == 0)
-        return false;
 
     // check to see if new region is completely contained within old region
@@ -814,6 +835,8 @@
 
 // should we call pmSourceCacheModel if it does not exist?
-bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal, int dx, int dy) {
-
+bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, 
+                 psMaskType maskVal, int dx, int dy)
+{
+    PS_ASSERT_PTR_NON_NULL(source, false);
     bool status;
 
@@ -904,4 +927,5 @@
 pmModel *pmSourceGetModel (bool *isPSF, const pmSource *source)
 {
+    PS_ASSERT_PTR_NON_NULL(source, NULL);
 
     pmModel *model;
