Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSub.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSub.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSub.c	(revision 30285)
@@ -112,4 +112,5 @@
         psLibFinalize();
 
+	fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "ppSub");
         exitValue = ppSubExitCode(exitValue);
         exit(exitValue);
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubFiles.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubFiles.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubFiles.c	(revision 30285)
@@ -125,4 +125,5 @@
     // FPA
     if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
+	psFree (view);
         return false;
     }
@@ -131,4 +132,5 @@
     view->chip = 0;
     if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
+	psFree (view);
         return false;
     }
@@ -137,4 +139,5 @@
     view->cell = 0;
     if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
+	psFree (view);
         return false;
     }
@@ -143,9 +146,11 @@
     view->readout = 0;
     if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-        return false;
-    }
-
-    ppSubFilesActivate(config, PPSUB_FILES_ALL, false);
-
+	psFree (view);
+        return false;
+    }
+
+    ppSubFilesActivate(config, PPSUB_FILES_ALL, false);
+
+    psFree (view);
     return true;
 }
@@ -162,4 +167,5 @@
     // Readout
     if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
+	psFree (view);
         return false;
     }
@@ -168,4 +174,5 @@
     view->readout = -1;
     if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
+	psFree (view);
         return false;
     }
@@ -174,4 +181,5 @@
     view->cell = -1;
     if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
+	psFree (view);
         return false;
     }
@@ -180,4 +188,5 @@
     view->chip = -1;
     if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
+	psFree (view);
         return false;
     }
@@ -222,4 +231,5 @@
     ppSubFilesActivate(config, PPSUB_FILES_ALL, false);
 
+    psFree (view);
     return true;
 }
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubInputDetections.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubInputDetections.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubInputDetections.c	(revision 30285)
@@ -118,4 +118,5 @@
 	if (!psMetadataCopy(sourcesHDU->header, imageHDU->header)) {
 	    psError(PPSUB_ERR_PROG, false, "Unable to copy header");
+	    psFree(view);
 	    return false;
 	}
@@ -130,8 +131,10 @@
     if (!psphotCopyResults (foundDetections, sourcesFile, photFile, view)) {
 	psError(PPSUB_ERR_PROG, false, "Unable to copy psphot outputs");
+	psFree(view);
 	return false;
     }
     // if no sources were found here, we report that back and let them handle it
 
+    psFree(view);
     return true;
 }
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubLoop.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubLoop.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubLoop.c	(revision 30285)
@@ -26,4 +26,5 @@
   pmReadout *out = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT");
   psphotSaveImage (NULL, out->image, name);
+  psFree(view);
   return true;
 }
@@ -111,4 +112,5 @@
         goto ESCAPE;
     }
+
     if (data->quality) {
         // Can't do anything at all
@@ -257,6 +259,8 @@
 	psError(psErrorCodeLast(), false, "Unable to generate mask statistics");
 	success = false;
+        psFree(view);
         goto ESCAPE;
       }
+      psFree(view);
     }
     // dumpout(config, "diff.4.fits");
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubMakePSF.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubMakePSF.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubMakePSF.c	(revision 30285)
@@ -79,4 +79,5 @@
     if (!detections || !detections->allSources) {
         psError(PPSUB_ERR_CONFIG, true, "No sources from which to determine PSF.");
+        psFree(view);
         return false;
     }
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubMatchPSFs.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubMatchPSFs.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubMatchPSFs.c	(revision 30285)
@@ -78,5 +78,4 @@
         return true;
     }
-
     psFree(view);
 
@@ -127,4 +126,5 @@
     if (!inSourceRO || !refSourceRO) {
         psError(PPSUB_ERR_DATA, false, "Unable to scale kernel, since no sources were provided.");
+        psFree(view);
         return false;
     }
@@ -166,5 +166,4 @@
     if (!psMetadataLookupBool(NULL, recipe, "SCALE")) {
         // No scaling requested
-        psFree(view);
         return true;
     }
@@ -221,4 +220,5 @@
         pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.INPUT.CONV"); // Cell for convolved input
         inConv = pmReadoutAlloc(cell);
+	psFree(inConv);
     }
     pmReadout *refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference convolved
@@ -226,4 +226,5 @@
         pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.REF.CONV"); // Cell for convolved ref.
         refConv = pmReadoutAlloc(cell);
+	psFree(refConv);
     }
 
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutForcedPhot.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutForcedPhot.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutForcedPhot.c	(revision 30285)
@@ -61,4 +61,5 @@
 	// XXX remove the pixels from photFile?
 	// XXX other cleanup operations?
+        psFree(view);
 	return true;
     }
@@ -89,4 +90,5 @@
     if (!psphotCopyResults (&foundDetections, outputFile, photFile, view)) {
 	psError(PPSUB_ERR_PROG, false, "Unable to copy psphot outputs");
+        psFree(view);
 	return false;
     }
@@ -97,4 +99,5 @@
     psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_PHOT", PS_META_REPLACE, "Time to do photometry", elapsed);
 
+    psFree(view);
     return true;
 }
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutInverse.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutInverse.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutInverse.c	(revision 30285)
@@ -36,4 +36,5 @@
     if (!pmAstromWriteWCS(invHDU->header, outFPA, outChip, WCS_TOLERANCE)) {
         psError(psErrorCodeLast(), false, "Unable to write WCS astrometry to PPSUB.INVERSE.");
+	psFree(view);
         return false;
     }
@@ -41,7 +42,9 @@
     if (!pmAstromReadWCS(invFPA, invChip, invHDU->header, 1.0)) {
         psError(psErrorCodeLast(), false, "Unable to read WCS astrometry.");
+	psFree(view);
         return false;
     }
 
+    psFree(view);
     return true;
 }
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutJpeg.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutJpeg.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutJpeg.c	(revision 30285)
@@ -139,4 +139,5 @@
     }
 
+    psFree(view);
     return true;
 }
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutPhotometry.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutPhotometry.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutPhotometry.c	(revision 30285)
@@ -109,12 +109,15 @@
         if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.DETECTIONS")) {
             psError(PPSUB_ERR_PROG, false, "Unable to copy PSPHOT.DETECTIONS");
+	    psFree(view);
             return false;
         }
         if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.HEADER")) {
             psError(PPSUB_ERR_PROG, false, "Unable to copy PSPHOT.HEADER");
+	    psFree(view);
             return false;
         }
         if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, PM_DETEFF_ANALYSIS)) {
             psError(PPSUB_ERR_PROG, false, "Unable to copy Detection Efficiency");
+	    psFree(view);
             return false;
         }
@@ -128,9 +131,10 @@
     }
 
+    psFree(view);
     return true;
 }
 
 #ifdef TESTING
-    // Record data about sources: not everything gets into the output CMF files
+// Record data about sources: not everything gets into the output CMF files
     {
         pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with the sources
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutSubtract.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutSubtract.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubReadoutSubtract.c	(revision 30285)
@@ -109,4 +109,5 @@
     pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSUB.OUTPUT"); // Output chip
     psFree(view);
+
     if (!outHDU || !inHDU) {
         psError(PPSUB_ERR_PROG, true, "Unable to find HDU at FPA level to copy astrometry.");
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubSetMasks.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubSetMasks.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubSetMasks.c	(revision 30285)
@@ -80,8 +80,10 @@
     if (!pmReadoutMaskInvalid(inRO, maskValue, satValue)) {
         psError(PPSUB_ERR_DATA, false, "Unable to mask non-finite pixels in input.");
+	psFree(view);
         return false;
     }
     if (!pmReadoutMaskInvalid(refRO, maskValue, satValue)) {
         psError(PPSUB_ERR_DATA, false, "Unable to mask non-finite pixels in reference.");
+	psFree(view);
         return false;
     }
@@ -94,4 +96,5 @@
     if (interpMode == PS_INTERPOLATE_NONE) {
         psError(PPSUB_ERR_CONFIG, false, "Unknown interpolation mode: %s", interpModeStr);
+	psFree(view);
         return false;
     }
@@ -104,8 +107,10 @@
     if (!pmReadoutInterpolateBadPixels(inRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) {
         psError(PPSUB_ERR_DATA, false, "Unable to interpolate bad pixels for input image.");
+	psFree(view);
         return false;
     }
     if (!pmReadoutInterpolateBadPixels(refRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) {
         psError(PPSUB_ERR_DATA, false, "Unable to interpolate bad pixels for reference image.");
+	psFree(view);
         return false;
     }
@@ -113,4 +118,5 @@
 #endif
 
+    psFree(view);
     return true;
 }
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubThreshold.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubThreshold.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubThreshold.c	(revision 30285)
@@ -98,4 +98,5 @@
     if (!in) {
         psError(PPSUB_ERR_UNKNOWN, false, "Unable to find readout.");
+	psFree(view);
         return false;
     }
@@ -104,4 +105,5 @@
     if (!ref) {
         psError(PPSUB_ERR_UNKNOWN, false, "Unable to find readout.");
+	psFree(view);
         return false;
     }
@@ -115,8 +117,10 @@
         if (!lowThreshold(in, thresh, maskVal, maskThresh, region, "input convolved image")) {
             psError(psErrorCodeLast(), false, "Unable to threshold input image.");
+	    psFree(view);
             return false;
         }
         if (!lowThreshold(ref, thresh, maskVal, maskThresh, region, "reference convolved image")) {
             psError(psErrorCodeLast(), false, "Unable to threshold input image.");
+	    psFree(view);
             return false;
         }
Index: /branches/eam_branches/ipp-20101205/ppSub/src/ppSubVarianceRescale.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSub/src/ppSubVarianceRescale.c	(revision 30284)
+++ /branches/eam_branches/ipp-20101205/ppSub/src/ppSubVarianceRescale.c	(revision 30285)
@@ -57,4 +57,5 @@
         // Nothing to renormalise
         psWarning("Renormalisation of the variance requested, but no variance provided.");
+	psFree(view);
         return true;
     }
@@ -69,4 +70,5 @@
     }
 
+    psFree(view);
     return true;
 }
