Undo: free and search the undo tree iteratively

Recursion depth equalled history length, so destroying or clearing a
buffer with a few hundred thousand undo steps overflowed the stack.
UndoSystem::clear() also freed only the first root branch, leaking the
root's siblings; it now frees the whole forest.

Audit finding M4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
Claude
2026-09-24 09:16:04 -07:00
committed by Kyle Isom
parent 0f2cc41ed1
commit 52089d3564
3 changed files with 48 additions and 37 deletions
+5
View File
@@ -15,3 +15,8 @@ struct UndoTree {
// created for it.
~UndoTree();
};
// Frees `first`, its whole child subtree, and every node on its `next`
// (sibling) chain. Iterative, so history depth cannot overflow the stack.
void FreeUndoForest(UndoNode *first);