Index: /trunk/ippTools/src/regtool.c
===================================================================
--- /trunk/ippTools/src/regtool.c	(revision 16199)
+++ /trunk/ippTools/src/regtool.c	(revision 16200)
@@ -628,6 +628,5 @@
     tess_id   = tess_id ? tess_id : newExp->tess_id;
     end_stage = end_stage ? end_stage : newExp->end_stage;
-
-    psFree(newExp);
+    // don't free newExp until just before we return, or these refs will break
 
     if (!rawExpInsert(config->dbh,
@@ -694,4 +693,5 @@
         }
         psError(PS_ERR_UNKNOWN, false, "database error");
+	psFree(newExp);
         return false;
     }
@@ -704,9 +704,11 @@
         }
         psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_id: %s", exp_id);
+	psFree(newExp);
         return false;
     }
 
     // should we stop here and proceed on to the chip stage?
-    if (psStrcasestr(end_stage, "reg")) {
+    // NULL for end_stage means go as far as possible
+    if (end_stage && psStrcasestr(end_stage, "reg")) {
         // then we are done here
         if (!psDBCommit(config->dbh)) {
@@ -715,4 +717,5 @@
         }
 
+	psFree(newExp);
         return true;
     }
@@ -737,4 +740,5 @@
         }
         psError(PS_ERR_UNKNOWN, false, "failed to queue chipPendingExp");
+	psFree(newExp);
         return false;
     }
@@ -742,7 +746,9 @@
     if (!psDBCommit(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-
+	psFree(newExp);
+        return false;
+    }
+
+    psFree(newExp);
     return true;
 }
