Index: trunk/psModules/src/camera/pmHDUGenerate.c
===================================================================
--- trunk/psModules/src/camera/pmHDUGenerate.c	(revision 9986)
+++ trunk/psModules/src/camera/pmHDUGenerate.c	(revision 11254)
@@ -272,10 +272,9 @@
 // Paste the source image into the target, according to the provided region.  The source is then updated to
 // reference the region within the target.
-static void pasteImage(psImage *target, // Target image, into which the paste is made
-                       psImage **sourcePtr,// Source image, from which the paste is made, and then changed
-                       psRegion *region // Image section into which to paste
-                      )
-{
-    psImage *source = *sourcePtr;       // Dereference pointer, for convenience
+static psImage *pasteImage(psImage *target, // Target image, into which the paste is made
+                           psImage *source,// Source image, from which the paste is made, and then changed
+                           psRegion *region // Image section into which to paste
+                          )
+{
     if (source->numCols != region->x1 - region->x0 || source->numRows != region->y1 - region->y0) {
         psString regionString = psRegionToString(*region);
@@ -287,8 +286,5 @@
 
     // Reference the HDU version, so that subsequent changes will touch the HDU
-    psFree(source);
-    *sourcePtr = psImageSubset(target, *region);
-
-    return;
+    return psImageSubset(target, *region);
 }
 
@@ -404,11 +400,17 @@
 
                 if (readout->image) {
-                    pasteImage(hduImages->data[i], &readout->image, trimsec);
+                    psImage *new = pasteImage(hduImages->data[i], readout->image, trimsec);
+                    psFree(readout->image);
+                    readout->image = new;
                 }
                 if (readout->mask) {
-                    pasteImage(hduMasks->data[i], &readout->mask, trimsec);
+                    psImage *new = pasteImage(hduMasks->data[i], readout->mask, trimsec);
+                    psFree(readout->mask);
+                    readout->mask = new;
                 }
                 if (readout->weight) {
-                    pasteImage(hduWeights->data[i], &readout->weight, trimsec);
+                    psImage *new = pasteImage(hduWeights->data[i], readout->weight, trimsec);
+                    psFree(readout->weight);
+                    readout->weight = new;
                 }
 
@@ -424,6 +426,6 @@
                 while ((bias = psListGetAndIncrement(biasIter)) &&
                         (biassec = psListGetAndIncrement(biassecsIter))) {
-                    pasteImage(hduImages->data[i], &bias, biassec);
-                    psListAdd(newBias, PS_LIST_TAIL, bias);
+                    psImage *new = pasteImage(hduImages->data[i], bias, biassec);
+                    psListAdd(newBias, PS_LIST_TAIL, new);
                 }
                 psFree(biasIter);
