Index: trunk/stac/src/stacCombine.c
===================================================================
--- trunk/stac/src/stacCombine.c	(revision 5745)
+++ trunk/stac/src/stacCombine.c	(revision 6887)
@@ -103,4 +103,7 @@
     psVector *deltas = psVectorAlloc(nImages, PS_TYPE_F32); // Will hold the errors in the statistics step
     psVector *mask = psVectorAlloc(nImages, PS_TYPE_U8); // Will hold the mask in the statistics step
+    pixels->n = nImages;
+    deltas->n = nImages;
+    mask->n = nImages;
 
     // Set up rejection masks
@@ -109,4 +112,5 @@
             // Allocate the rejection masks, if required
             *rejected = psArrayAlloc(nImages);
+            (*rejected)->n = nImages;
         } else {
             assert((*rejected)->n != nImages);
@@ -202,10 +206,10 @@
     char chiName[MAXCHAR];              // Filename of chi^2 image
     sprintf(chiName,"chi2_%d.fits",iteration);
-    psFits *chiFile = psFitsAlloc(chiName);
-    if (!psFitsWriteImage(chiFile, NULL, chi2 , 0)) {
+    psFits *chiFile = psFitsOpen(chiName, "w");
+    if (!psFitsWriteImage(chiFile, NULL, chi2 , 0, NULL)) {
         psErrorStackPrint(stderr, "Unable to write image: %s\n", chiName);
     }
     psTrace("stac.combine", 1, "Chi^2 image written to %s\n", chiName);
-    psFree(chiFile);
+    psFitsClose(chiFile);
     psFree(chi2);
 #endif
