Add some missing headers found by GCC
Clean up some memory leaks in the XPath tests