diff --git a/app/Tree.php b/app/Tree.php
index <HASH>..<HASH> 100644
--- a/app/Tree.php
+++ b/app/Tree.php
@@ -604,6 +604,7 @@ class Tree {
 			}
 		}
 		fwrite($stream, $buffer . '0 TRLR' . WT_EOL);
+		$stmt->closeCursor();
 	}
 
 	/**
Upgrade wizard fails when more than one tree