Index: trunk/ppImage/src/ppImage.c
===================================================================
--- trunk/ppImage/src/ppImage.c	(revision 6125)
+++ trunk/ppImage/src/ppImage.c	(revision 6148)
@@ -1,6 +1,41 @@
 #include "ppImage.h"
+
+psMemId ppMemAlloc(const psMemBlock *ptr)
+{
+    psLogMsg(__func__, PS_LOG_INFO,
+             "Allocated memory block %d: %ld references\n"
+             "\tFile %s, line %d, size %d\n"
+             "\tPosts: %lx %lx %lx\n"
+             "\tLast operation: %s:%d\n",
+             ptr->id, ptr->refCounter, ptr->file, ptr->lineno, ptr->userMemorySize, ptr->startblock,
+             ptr->endblock, *(void**)((int8_t *)(ptr + 1) + ptr->userMemorySize),
+             ptr->lastopFile, ptr->lastopLine);
+    return 0;
+}
+
+psMemId ppMemFree(const psMemBlock *ptr)
+{
+    psLogMsg(__func__, PS_LOG_INFO,
+             "Freed memory block %d: %ld references\n"
+             "\tFile %s, line %d, size %d\n"
+             "\tPosts: %lx %lx %lx\n"
+             "\tLast operation: %s:%d\n",
+             ptr->id, ptr->refCounter-1, ptr->file, ptr->lineno, ptr->userMemorySize, ptr->startblock,
+             ptr->endblock, *(void**)((int8_t *)(ptr + 1) + ptr->userMemorySize),
+             ptr->lastopFile, ptr->lastopLine);
+    return 0;
+}
+
 
 int main(int argc, char **argv)
 {
+#if 0
+    psMemAllocCallbackSet(ppMemAlloc);
+    psMemFreeCallbackSet(ppMemFree);
+//    psMemAllocCallbackSetID(6967);
+//    psMemFreeCallbackSetID(6967);
+    psMemAllocCallbackSetID(51804);
+    psMemFreeCallbackSetID(51804);
+#endif
 
     ppData data;
Index: trunk/ppImage/src/ppImageLoop.c
===================================================================
--- trunk/ppImage/src/ppImageLoop.c	(revision 6125)
+++ trunk/ppImage/src/ppImageLoop.c	(revision 6148)
@@ -1,3 +1,5 @@
 # include "ppImage.h"
+
+#define MEM_LEAKS 1
 
 psMemId ppMemPrint(const psMemBlock *ptr)
@@ -63,8 +65,4 @@
     for (int i = 0; i < chips->n; i++) {
 
-        if (i > 6) {
-            continue;
-        }
-
         if (processChip >= 0 && i != processChip) {
             continue;
@@ -84,4 +82,6 @@
         pmChip *maskChip  = data->mask->fpa->chips->data[i];
         pmChip *flatChip  = data->flat->fpa->chips->data[i];
+
+        ppMemPrint((psMemBlock*)inputChip-1);
 
         psArray *cells = inputChip->cells;
@@ -107,8 +107,10 @@
 
             // 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
         }
 
@@ -118,5 +120,6 @@
         // XXX EAM: Photometry goes here!
 
-        // A kludge to get the write to behave wrt the concepts
+        // A kludge to get the write to behave wrt 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;
         data->input->fpa->camera = NULL;
@@ -125,6 +128,8 @@
 
         // Now I can blow away the mosaic so I can then read more.
-        psFree(chips->data[i]);
+#ifndef MEM_LEAKS
+        pmChipFreeCells(inputChip);
         ppMemPrint((psMemBlock*)chips->data[i]-1);
+#endif
     }
 
@@ -152,8 +157,10 @@
 
     // 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);
