I'm seeing pointer being freed was not allocated sometimes when trying to set attribute. In particular when trying to set attribute that's been removed from document and added to fragment like this:
let xml = #"""
<item>
<item a="1"/>
</item>
"""#
let document = try XML.Document(string: xml)!
let three = document.search(xpath: "//*[@a=\"1\"]").first!
three.remove()
let fragment = DocumentFragment(children: { three })
three["a"] = "8"
I can avoid the crash if I create the document fragment like this instead:
let xmlDoc = document.rawValue.bindMemory(to: _xmlDoc.self, capacity: 1)
let fragment = DocumentFragment(rawValue: xmlNewDocFragment(xmlDoc))!
I guess it's bad to move and xml node belonging to a document to another node that doesn't belong to a document? Please let me know if you have a better idea of what's wrong and why the fix works.