More xpath memory fixes

Fix several memory leaks and free issues.

Includes additional fixes for AXISC-1602 and parts of AXISC-1669
5 files changed