Index: branches/eam_branches/gDiff.20200202/src/gDiffExtras.c
===================================================================
--- branches/eam_branches/gDiff.20200202/src/gDiffExtras.c	(revision 41413)
+++ branches/eam_branches/gDiff.20200202/src/gDiffExtras.c	(revision 41414)
@@ -21,6 +21,7 @@
     if (!targetRO) {
 	pmCell *targetCell = pmFPAviewThisCell(view, target->fpa);
-	targetRO = pmReadoutAlloc(targetCell);
+	targetRO = pmReadoutAlloc(targetCell); // returns a reference and adds one to the cell
 	psAssert(targetRO, "programming error: could not make target readout");
+	psFree (targetRO); // free the reference
     }
 
@@ -55,5 +56,7 @@
     if (hdu) {
 	psMetadata *header = psMetadataLookupMetadata(NULL, targetRO->analysis, "PSPHOT.HEADER"); // Header
-	hdu->header = psMetadataCopy(hdu->header, header);
+	if (header) {
+	  hdu->header = psMetadataCopy(hdu->header, header);
+	}
     }
 
