Skip to content

Commit

Permalink
Set up finalizer for the result of LightXML.parse_string()
Browse files Browse the repository at this point in the history
  • Loading branch information
samoconnor committed Mar 13, 2016
1 parent a879038 commit 146af78
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/XMLDict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ Base.show(io::IO, x::XMLDictElement) = show(io, x.x)

# Parse "xml" string into LightXML.XMLDocument object.

parse_xml(xml::AbstractString) = wrap(LightXML.parse_string(xml))
function parse_xml(xml::AbstractString)
doc = LightXML.parse_string(xml)
finalizer(doc, LightXML.free)
return wrap(doc)
end



Expand Down Expand Up @@ -105,7 +109,10 @@ XMLDict.get(x::XMLDocument, tag, default) = get(root(x), tag, default)
# Return Dict representation of "xml" string.

function xml_dict(xml::AbstractString, dict_type::Type=OrderedDict; options...)
xml_dict(parse_xml(xml), dict_type; options...)
doc = parse_xml(xml)
r = xml_dict(doc, dict_type; options...)
finalize(doc)
return r
end


Expand Down

0 comments on commit 146af78

Please sign in to comment.