Fix xmlDestroyNode not removing nodes from saved XML files#5002
Open
QueryOfficial wants to merge 1 commit into
Open
Fix xmlDestroyNode not removing nodes from saved XML files#5002QueryOfficial wants to merge 1 commit into
QueryOfficial wants to merge 1 commit into
Conversation
…ocument synchronization - Updated the destructor to first delete wrapper children, allowing each child to unlink its own tinyxml2 node before the parent is removed. - Added logic to keep the underlying document in sync when nodes are destroyed via xmlDestroyNode, ensuring m_pNode is nullified before deletion to prevent unlinking issues during document teardown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
xmlDestroyNodeso deleted nodes are actually removed from the saved XML file.CXMLNodeImpl::~CXMLNodeImpl()now keeps the underlying tinyxml2 document in sync with the wrapper tree: wrapper children are deleted first (each child unlinks its own tinyxml2 node), then the destroyed node is removed from its parent viaDeleteChild().m_pNodeis nullified before wrapper teardown completes soDeleteWrapper/ full document unload does not double-unlink.Motivation
Fixes #5001.
After the tinyxml → tinyxml2 migration (
#4942), per-node DOM removal was dropped from the destructor to avoid ownership conflicts during full file teardown. That path is still safe viaDeleteWrapper, butxmlDestroyNodeonly removed the MTA wrapper fromm_Children— the tinyxml2 tree was unchanged, soxmlSaveFilewrote stale content.Symptoms:
xmlDestroyNode+xmlSaveFileleaves deleted children in the filemeta.xmlstill lists a<map>entry afterxmlDestroyNode, while the.mapfile was already removed (addResourceMaptreats it as a duplicate)Test plan
Run the reproduction script in a test resource and confirm the chat output is
map exists: falseand the saved file contains only<meta/>.In the map editor, place an object, save, then save again. The second save should complete without the "Map resource could not be saved" error.
Load an XML file with
xmlLoadFileand unload it withxmlUnloadFilewithout manually destroying child nodes. Confirm there is no crash or double-free.Load XML with
xmlLoadString, destroy a child node withxmlDestroyNode, and confirm the node is removed from the in-memory tree.Regression checks: ACL save, resource settings via
getResourceInfo()/CopyNode, and basicxmlCreateChild+xmlSaveFileflows should still work as before.Checklist
Reproduction script