Cast LibXML::Doc* to LibXML::Node*#16412
Cast LibXML::Doc* to LibXML::Node*#16412toddsundsted wants to merge 0 commit intocrystal-lang:masterfrom
LibXML::Doc* to LibXML::Node*#16412Conversation
There was a problem hiding this comment.
Urgh, I wish a linter would notice "always true" and "always false" comparisons and warn about them.
Thank you @toddsundsted 🙇
|
This is an easy trap. I'm wondering if |
Sorry! Got careless. |
|
ugh again :-( this is the last time, I swear! |
LibXML.xmlFreeNode(node)on line 60 is never called becausenode.value.docis aLibXML::Doc*not aLibXML::Node*and so the comparison always evaluates tofalse. The equality method inComparableonly kicks in if the receiver and the one parameter are the same type. This PR castsdocto the correct type of the comparison.The following spec demonstrates the problem. If you adjust the number of iterations, the memory allocated scales linearly with iterations and never plateaus. Unlinking nodes by iterating over children and xpath nodes both demonstrate the problem.