Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 9946)
+++ /trunk/ippTools/src/dettool.c	(revision 9947)
@@ -135,5 +135,7 @@
             psAbort(argv[0], "invalid option (this should not happen)");
     }
-psFree(config); pmConfigDone();
+
+    psFree(config);
+    pmConfigDone();
     psLibFinalize();
 
@@ -832,5 +834,5 @@
     if (psArrayLength(detRuns) != 1) {
         psAbort(config->argv[0], "found more then one detRun matching det_id %d(this should not happen)", (psS32)atoi(det_id));
-        return false;
+        return false;                   // unreachable
     }
    
@@ -858,5 +860,6 @@
     }
     if (exp_type) {
-        detRun->exp_type = exp_type;
+        psFree(detRun->exp_type);
+        detRun->exp_type = psStringCopy(exp_type);
     }
 
@@ -867,5 +870,6 @@
     }
     if (filter) {
-        detRun->filter = filter;
+        psFree(detRun->filter);
+        detRun->filter = psStringCopy(filter);
     }
 
@@ -912,5 +916,6 @@
     }
     if (object) {
-        detRun->object = object;
+        psFree(detRun->object);
+        detRun->object = psStringCopy(object);
     }
 
@@ -924,5 +929,5 @@
         // pass through NULL as this is an optional field
         if (registeredStr) {
-            psFree(registered);
+            psFree(detRun->registered);
             registered = psTimeFromISO(registeredStr, PS_TIME_UTC);
             detRun->registered = psMemIncrRefCounter(registered);
@@ -940,5 +945,5 @@
         // pass through NULL as this is an optional field
         if (use_beginStr) {
-            psFree(use_begin);
+            psFree(detRun->use_begin);
             use_begin = psTimeFromISO(use_beginStr, PS_TIME_UTC);
             detRun->use_begin = psMemIncrRefCounter(use_begin);
@@ -956,5 +961,5 @@
         // pass through NULL as this is an optional field
         if (use_endStr) {
-            psFree(use_end);
+            psFree(detRun->use_end);
             use_end = psTimeFromISO(use_endStr, PS_TIME_UTC);
             detRun->use_end = psMemIncrRefCounter(use_end);
@@ -1015,38 +1020,36 @@
     }
 
-    {
     // print the new det_id
-    psArray *detRuns = NULL;
+    psArray *newDetRuns = NULL;
     {
         psMetadata *where = psMetadataAlloc();
         psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==", newDet_id);
-        detRuns = psDBSelectRows(config->dbh, "detRun", where, 0);
+        newDetRuns = psDBSelectRows(config->dbh, "detRun", where, 0);
         psFree(where);
     }
-    if (!detRuns) {
+    if (!newDetRuns) {
         psError(PS_ERR_UNKNOWN, false, "can't find the detRun we just created");
         return false;
     }
     // sanity check the result... we should have only found one det_id
-    if (psArrayLength(detRuns) != 1) {
+    if (psArrayLength(newDetRuns) != 1) {
         psAbort(config->argv[0], "found more then one detRun matching det_id %ld(this should not happen)", newDet_id);
-        return false;
+        return false;                   // unreachable
     }
 
     // convert det_id to a string externaly
-    if (!convertDetIdToStr(detRuns)) {
+    if (!convertDetIdToStr(newDetRuns)) {
         psError(PS_ERR_UNKNOWN, false, "failed to convert det_id to a string");
-        psFree(detRuns);
+        psFree(newDetRuns);
         return false;
     }
 
     // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, detRuns, "detRun", !simple)) {
+    if (!ippdbPrintMetadatas(stdout, newDetRuns, "detRun", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "failed to print array");
-        psFree(detRuns);
-        return false;
-    }
-    psFree(detRuns);
-    }
+        psFree(newDetRuns);
+        return false;
+    }
+    psFree(newDetRuns);
 
     return true;
