Fix XPath.XmlDocument concurrency problem and memory leak

Fix XPath.XmlDocument concurrency problem and memory leak