Skip to content

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jan 29, 2020

The fix for bug #49634 solved a double-free by copying the node with
xmlDocCopyNodeList(), but the copied node is later freed by calling
xmlFreeNode() instead of xmlFreeNodeList(), thus leaking memory.
However, there is no need to treat the node as node list, i.e. to copy
also the node's siblings; just creating a recursive copy of the node
with xmlDocCopyNode() is sufficient, while that also avoids the leak.

The fix for bug #49634 solved a double-free by copying the node with
`xmlDocCopyNodeList()`, but the copied node is later freed by calling
`xmlFreeNode()` instead of `xmlFreeNodeList()`, thus leaking memory.
However, there is no need to treat the node as node list, i.e. to copy
also the node's siblings; just creating a recursive copy of the node
with `xmlDocCopyNode()` is sufficient, while that also avoids the leak.
@cmb69
Copy link
Member Author

cmb69 commented Jan 29, 2020

@m6w6, what do you think?

@not-implemented
Copy link
Contributor

@cmb69: Cool tnx :-) ... By the way: I never understood, why a recursive copy is made here at all ... this is also a performance issue when passing a bigger tree into a PHP function.

In Bug #49634 it is not described, why this was made. But the comments describe the performance problem, too, after the fix.

@cmb69
Copy link
Member Author

cmb69 commented Jan 29, 2020

@not-implemented, I first tried a shallow copy, but that caused xslt011.phpt to fail (the from the Input Document line was missing). However, the attached test case (your script) runs in less than 1 second with this PR; apparently, the memory leak caused the serious performance regression.

@not-implemented
Copy link
Contributor

@cmb69: Ah okay, cool. Then this should be fine :-) Many thanks.

@m6w6
Copy link
Contributor

m6w6 commented Jan 30, 2020

Awesome, LGTM!

@cmb69
Copy link
Member Author

cmb69 commented Jan 30, 2020

Thanks! Applied as 8226e70.

@cmb69 cmb69 closed this Jan 30, 2020
@cmb69 cmb69 deleted the cmb/70078 branch January 30, 2020 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants