Fix memleaks and double-free issues with xpath
4 files changed