Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.160
diff -u -F^f -r1.160 form.inc
--- includes/form.inc	16 Nov 2006 09:06:59 -0000	1.160
+++ includes/form.inc	22 Nov 2006 07:35:06 -0000
@@ -70,11 +70,11 @@ function drupal_get_form($form_id) {
   // then go on to the one that was requested if everything works.
 
   $form_build_id = md5(mt_rand());
-  if (isset($_POST['form_build_id']) && isset($_SESSION['form'][$_POST['form_build_id']]) && $_POST['form_id'] == $form_id) {
+  if (isset($_POST['form_build_id']) && isset($_SESSION['form'][$_POST['form_build_id']]['args']) && $_POST['form_id'] == $form_id) {
     // There's a previously stored multi-step form. We should handle
     // IT first.
     $stored = TRUE;
-    $args = $_SESSION['form'][$_POST['form_build_id']];
+    $args = $_SESSION['form'][$_POST['form_build_id']]['args'];
     $form = call_user_func_array('drupal_retrieve_form', $args);
   }
   else {
@@ -84,7 +84,7 @@ function drupal_get_form($form_id) {
     $args = func_get_args();
     $form = call_user_func_array('drupal_retrieve_form', $args);
     if (isset($form['#multistep']) && $form['#multistep']) {
-      $_SESSION['form'][$form_build_id] = $args;
+      $_SESSION['form'][$form_build_id] = array('timestamp' => time(), 'args' => $args);
       $form['#build_id'] = $form_build_id;
     }
     $stored = FALSE;
@@ -115,6 +115,20 @@ function drupal_get_form($form_id) {
 
 
 /**
+ * Remove old form information from the $_SESSION['form'] array
+ */
+function _drupal_clean_form_sessions() {
+  if (isset($_SESSION['form'])) {
+    foreach ($_SESSION['form'] as $build_id => $data) {
+      if ($data['timestamp'] < (time() - 84600)) {
+        unset($_SESSION['form'][$build_id]);
+      }
+    }
+  }
+}
+
+
+/**
  * Retrieves a form using a form_id, populates it with $form_values,
  * processes it, and returns any validation errors encountered. This
  * function is the programmatic counterpart to drupal_get_form().
