tid-kijyun / Kanna

Kanna(鉋) is an XML/HTML parser for Swift.
MIT License
2.42k stars 220 forks source link

memory leaks #157

Open gbuela opened 7 years ago

gbuela commented 7 years ago

Description:

I'm getting memory leaks here:

0 libsystem_malloc.dylib malloc_zone_malloc 1 libsystem_malloc.dylib malloc 2 libxml2.2.dylib xmlStrndup 3 libxml2.2.dylib xmlSplitQName 4 libxml2.2.dylib xmlSAX2StartElement 5 libxml2.2.dylib htmlParseStartTag 6 libxml2.2.dylib htmlParseContentInternal 7 libxml2.2.dylib htmlParseDocument 8 libxml2.2.dylib htmlDoRead 9 Kanna specialized libxmlXMLDocument.init(xml:url:encoding:option:) 10 Kanna specialized libxmlHTMLDocument.init(html:url:encoding:option:) 11 Kanna libxmlHTMLDocument.init(html:url:encoding:option:) /Users/.../Pods/Kanna/Sources/Kanna/Kanna.swift:0 12 Kanna libxmlHTMLDocument.__allocating_init(html:url:encoding:option:) /Users/.../Pods/Kanna/Sources/Kanna/Kanna.swift:0 13 Kanna HTML(html:encoding:option:) /Users/.../Pods/Kanna/Sources/Kanna/Kanna.swift:125

Installation method:

Library version:

Xcode version:

tid-kijyun commented 7 years ago

@gbuela

Thanks for letting me know. However I can not reproduce it for now. I'd like to know more about leak situation.

  1. Does it occur even with simple HTML/XML parsing?
  2. Could you present code to reproduce?
  3. Please let us know if there is additional information.

Thanks

bfichter commented 2 years ago

I realize this is an old issue at this point, but I am experiencing this as well with 5.2.7. It happens for me after calling htmlDocument.body?.removeChild(childElement).

It seems removeChild doesn't fully cleanup the libxml2 memory. Possibly it should call xmlFreeNode instead of xmlFree?

tid-kijyun commented 2 years ago

@bfichter You're right. Thanks for the helpful advice!