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

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

@jessegrosjean

Description

@jessegrosjean

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions