test-path-util: fix a mem leak and avoid confusing coverity

Found with coverity. Fixes CID#1237754 and #1237790