Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

pointer being freed was not allocated: Error and workaround #16

Open
jessegrosjean opened this issue Aug 20, 2021 · 0 comments
Open

pointer being freed was not allocated: Error and workaround #16

jessegrosjean opened this issue Aug 20, 2021 · 0 comments

Comments

@jessegrosjean
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant