Index: trunk/psphot/src/LocalSky.c
===================================================================
--- trunk/psphot/src/LocalSky.c	(revision 4642)
+++ trunk/psphot/src/LocalSky.c	(revision 4901)
@@ -18,13 +18,9 @@
     //  psImage *subImageNoise = psImageSubset(imdata->noise, srcRegion);
 
-    psImage *subImage = psImageSubset(imdata->image, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
-    psImage *subImageMask = psImageSubset(imdata->mask, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
-    psImage *subImageNoise = psImageSubset(imdata->noise, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
-
-    mySource->pixels = subImage;
-    mySource->mask = subImageMask;
-    mySource->noise = subImageNoise;
+    mySource->pixels = psImageSubset(imdata->image, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
+    mySource->noise  = psImageSubset(imdata->noise, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
+    mySource->mask   = psImageSubset(imdata->mask,  srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
+
     psFree (srcRegion);
-
     return(mySource);
 }
@@ -48,10 +44,12 @@
     myStats = psImageStats(myStats, image, mask, 0xff);
     psImageMaskRegion (mask, srcRegion, AND, 0x7f);
-    psFree (srcRegion);
 
     psF64 tmpF64;
     p_psGetStatValue(myStats, &tmpF64);
+
+    psFree (myStats);
+    psFree (srcRegion);
+
     if (isnan(tmpF64)) return (false);
-
     source->moments = pmMomentsAlloc();
     source->moments->Sky = (psF32) tmpF64;
