Index: trunk/psLib/src/image/psImage.c
===================================================================
--- trunk/psLib/src/image/psImage.c	(revision 791)
+++ trunk/psLib/src/image/psImage.c	(revision 812)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-26 22:55:46 $
+ *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-29 01:09:53 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -75,4 +75,18 @@
     }
 
+    if (image->type.type == PS_TYPE_PTR) {
+        // 2-D array of pointers -- must dereference
+        unsigned int oldNumRows = image->numRows;
+        unsigned int oldNumCols = image->numCols;
+        psPTR* rowPtr;
+
+        for(unsigned int row=0;row<oldNumRows;row++) {
+            rowPtr = image->data.PTR[row];
+            for (unsigned int col=0;col<oldNumCols;col++) {
+                psMemDecrRefCounter(rowPtr[col]);
+            }
+        }
+    }
+
     psImageFreeChildren(image);
 
@@ -84,5 +98,7 @@
 }
 
-psImage* psImageRealloc(psImage* old,unsigned int numCols, unsigned int numRows,
+psImage* psImageRecycle(psImage* old,
+                        unsigned int numCols,
+                        unsigned int numRows,
                         const psElemType type)
 {
@@ -96,6 +112,21 @@
 
     if (old->type.dimen != PS_DIMEN_IMAGE) {
-        psError(__func__,"Can not realloc image because image is not an image.");
-        return NULL;
+        psError(__func__,"Can not realloc image because input is not an image.");
+        return NULL;
+    }
+
+    if (old->type.type == PS_TYPE_PTR) {
+        // 2-D array of pointers -- must dereference
+        unsigned int oldNumRows = old->numRows;
+        unsigned int oldNumCols = old->numCols;
+        psPTR* rowPtr;
+
+        for(unsigned int row=0;row<oldNumRows;row++) {
+            rowPtr = old->data.PTR[row];
+            for (unsigned int col=0;col<oldNumCols;col++) {
+                psMemDecrRefCounter(rowPtr[col]);
+                rowPtr[col] = NULL;
+            }
+        }
     }
 
@@ -163,5 +194,5 @@
     elementSize = PSELEMTYPE_SIZEOF(image->type.type);
 
-    out = psImageRealloc(out,numCols,numRows,image->type.type);
+    out = psImageRecycle(out,numCols,numRows,image->type.type);
 
     // set the parent information into the child output image
@@ -245,5 +276,5 @@
     }
 
-    output = psImageRealloc(output,numCols,numRows,type);
+    output = psImageRecycle(output,numCols,numRows,type);
 
     // cover the trival case of copy of the same datatype.
@@ -470,25 +501,25 @@
     switch (bitPix) {
     case BYTE_IMG:
-        psImageRealloc(output,numCols,numRows,PS_TYPE_U8);
+        psImageRecycle(output,numCols,numRows,PS_TYPE_U8);
         (void)fits_read_subset(fptr, TBYTE, firstPixel, lastPixel, increment,
                                NULL, output->data.v, &anynull, &status);
         break;
     case SHORT_IMG:
-        psImageRealloc(output,numCols,numRows,PS_TYPE_S16);
+        psImageRecycle(output,numCols,numRows,PS_TYPE_S16);
         (void)fits_read_subset(fptr, TSHORT, firstPixel, lastPixel, increment,
                                NULL, output->data.v, &anynull, &status);
         break;
     case LONG_IMG:
-        psImageRealloc(output,numCols,numRows,PS_TYPE_S32);
+        psImageRecycle(output,numCols,numRows,PS_TYPE_S32);
         (void)fits_read_subset(fptr, TINT, firstPixel, lastPixel, increment,
                                NULL, output->data.v, &anynull, &status);
         break;
     case FLOAT_IMG:
-        psImageRealloc(output,numCols,numRows,PS_TYPE_F32);
+        psImageRecycle(output,numCols,numRows,PS_TYPE_F32);
         (void)fits_read_subset(fptr, TFLOAT, firstPixel, lastPixel, increment,
                                NULL, output->data.v, &anynull, &status);
         break;
     case DOUBLE_IMG:
-        psImageRealloc(output,numCols,numRows,PS_TYPE_F64);
+        psImageRecycle(output,numCols,numRows,PS_TYPE_F64);
         (void)fits_read_subset(fptr, TDOUBLE, firstPixel, lastPixel, increment,
                                NULL, output->data.v, &anynull, &status);
