Index: trunk/ppImage/src/ppImageLoop.c
===================================================================
--- trunk/ppImage/src/ppImageLoop.c	(revision 6260)
+++ trunk/ppImage/src/ppImageLoop.c	(revision 6396)
@@ -7,4 +7,5 @@
 #include "ppImageDetrend.h"
 #include "ppImage.h"
+#include "ppMem.h"
 
 #define MEM_LEAKS 1
@@ -101,10 +102,8 @@
 
             // Need to free detrend cells here so we have enough memory to do other stuff
-#ifndef MEM_LEAKS
             psFree(detrend.bias);
             psFree(detrend.dark);
             psFree(detrend.mask);
             psFree(detrend.flat);
-#endif
         }
 
@@ -114,5 +113,5 @@
         // XXX EAM: Photometry goes here!
 
-        // A kludge to get the write to behave wrt the concepts --- we've changed the camera format, so
+        // XXX A kludge to get the write to behave w.r.t. the concepts --- we've changed the camera format, so
         // the concepts don't know what on earth to do.
         const psMetadata *camera = data->input->fpa->camera;
@@ -122,43 +121,7 @@
 
         // Now I can blow away the mosaic so I can then read more.
-#ifndef MEM_LEAKS
-        pmChipFreeCells(inputChip);
-#endif
+        psFree(inputChip);
     }
-
-#if 0
-    // Write out the mosaicked chip, just to see; this wouldn't normally happen
-    psFits *mosaicFile = psFitsOpen("mosaic.fits", "w");
-    for (int i = 0; i < chips->n; i++) {
-        pmChip *chip = chips->data[i];
-        if (! chip || ! chip->exists || ! chip->process) {
-            continue;
-        }
-#if 0
-        psArray *cells = chip->cells;
-        pmCell *cell = cells->data[0];
-        psArray *readouts = cell->readouts;
-        pmReadout *readout = readouts->data[0];
-        psImage *image = readout->image;
-#else
-        psImage *image = chip->hdu->images->data[0];
-#endif
-        psFitsWriteImage(mosaicFile, NULL, image, 0);
-
-    }
-#endif
-
-    // Free the detrend FPA and chips
-#ifndef MEM_LEAKS
-    psFree(data->bias);
-    psFree(data->dark);
-    psFree(data->mask);
-    psFree(data->flat);
-#endif
-
-    psFitsClose(data->output);
 
     return true;
 }
-
-/* if we allow per-readout loads, we need to load detrend images here */
