Index: trunk/psLib/src/image/psImage.c
===================================================================
--- trunk/psLib/src/image/psImage.c	(revision 693)
+++ trunk/psLib/src/image/psImage.c	(revision 700)
@@ -7,6 +7,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-15 00:14:56 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-15 02:10:27 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -65,20 +65,7 @@
 void psImageFree(psImage *image)
 {
-    int i = 0;
-    int nChildren = 0;
-    psImage **children = NULL;
-
-    if(image != NULL) {
-        nChildren = image->nChildren;
-        children = image->children;
-
-        for(i=0; i<nChildren; i++) {
-            psImageFree(children[i]);
-        }
-
-        psFree(image->data.v[0]);
-        psFree(image->data.v);
-
-    }
+    psImageFreeChildren(image);
+    psImageFreePixels(image);
+    psFree(image);
 }
 
@@ -91,6 +78,6 @@
     unsigned int inputColOffset;        // offset in bytes to first subset pixel in input row
 
-    if (image == NULL) {
-        psError(__func__,"Can not subset image because input image is NULL.");
+    if (image == NULL || image->data.v == NULL) {
+        psError(__func__,"Can not subset image because input image or its pixel buffer is NULL.");
         return NULL;
     }
@@ -139,2 +126,41 @@
     return (out);
 }
+
+void psImageFreePixels(psImage *restrict image)
+{
+    if (image == NULL || image->data.v == NULL) {
+        return;
+    }
+
+    psFree(image->data.v[0]);
+    psFree(image->data.v);
+    image->data.v = NULL;
+
+    // xxx - is this proper?
+    *(unsigned int*)&image->numRows = 0;
+    *(unsigned int*)&image->numCols = 0;
+}
+
+int psImageFreeChildren(psImage* image)
+{
+    int i = 0;
+    int nChildren = 0;
+    psImage **children = NULL;
+    int numFreed = 0;
+
+    if (image == NULL) {
+        return numFreed;
+    }
+
+    nChildren = image->nChildren;
+    children = image->children;
+
+    for(i=0; i<nChildren; i++) {
+        if (children[i] != NULL) {
+            numFreed++;
+            psImageFree(children[i]);
+        }
+    }
+
+    return numFreed;
+}
