Index: /trunk/psModules/src/detrend/pmDetrendDB.c
===================================================================
--- /trunk/psModules/src/detrend/pmDetrendDB.c	(revision 16845)
+++ /trunk/psModules/src/detrend/pmDetrendDB.c	(revision 16846)
@@ -118,5 +118,5 @@
     int status, exit_status;
     psString line = NULL;
-    char *time = psTimeToISO (&options->time);
+    psString time = psTimeToISO (&options->time);
 
     char *type = NULL;
@@ -149,5 +149,9 @@
         psStringAppend(&line, " -airmass %f", options->twilight);
     }
-    
+
+    psIOBuffer *buffer = NULL;
+    psPipe *pipe = NULL;
+    psMetadata *answer = NULL;
+
     if (!pmConfigDatabaseCommand(&line, config)) {
         psError (PS_ERR_IO, false, "error building detrend command %s", line);
@@ -163,6 +167,6 @@
 
     // use psPipe to exec the command, wait for response
-    psIOBuffer *buffer = psIOBufferAlloc (512);
-    psPipe *pipe = psPipeOpen (line);
+    buffer = psIOBufferAlloc (512);
+    pipe = psPipeOpen (line);
     if (!pipe) {
         psError (PS_ERR_IO, false, "error calling command %s", line);
@@ -184,5 +188,5 @@
 
     nFail = 0;
-    psMetadata *answer = psMetadataConfigParse (NULL, &nFail, buffer->data, false);
+    answer = psMetadataConfigParse (NULL, &nFail, buffer->data, false);
     if (!answer) {
         psError(PS_ERR_IO, false, "failed to parse response from detselect\n");
@@ -234,4 +238,5 @@
 
 failure:
+    psFree (answer);
     psFree (results);
     psFree (pipe);
@@ -260,5 +265,5 @@
     psStringAppend (&line, "detselect -select %s", detID);
     if (classID && strlen(classID) > 0) {
-	psStringAppend(&line, " -class_id %s", classID);
+        psStringAppend(&line, " -class_id %s", classID);
     }
     pmConfigDatabaseCommand(&line, config);
@@ -273,5 +278,5 @@
         goto failure;
     }
-    
+
     // timeout somewhat longer than 2sec.  this could still be too short....
     status = psIOBufferReadEmpty (buffer, 2000, pipe->fd_stdout);
@@ -302,5 +307,5 @@
     psMetadataItem *item = psMetadataLookup (answer, "detNormalizedImfile");
     if ((item->type == PS_DATA_METADATA_MULTI) && (item->data.list->n > 1)) {
-	psError(PS_ERR_IO, false, "detselect returned too many files\n");
+        psError(PS_ERR_IO, false, "detselect returned too many files\n");
         goto failure;
     }
