diff options
-rw-r--r-- | src/core/dom/Node.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/core/dom/Node.cpp b/src/core/dom/Node.cpp index dcf4261..8df0787 100644 --- a/src/core/dom/Node.cpp +++ b/src/core/dom/Node.cpp @@ -257,13 +257,21 @@ void NodeManager::purgeDeleted() { // Perform the actual deletion if the recursion level is zero if (deletionRecursionDepth == 0 && !deleted.empty()) { + // Increment the recursion depth so this function does not get called + // again while deleting nodes ScopedIncrement incr{deletionRecursionDepth}; - for (Node *n : deleted) { + + // Deleting nodes might add new nodes to the deleted list, thus the + // iterator would get invalid and we have to use this awkward + // construction + while (!deleted.empty()) { + auto it = deleted.begin(); + Node *n = *it; + deleted.erase(it); marked.erase(n); nodes.erase(n); delete n; } - deleted.clear(); } } |