tree: free in error conditions As reported by coverity, we would leak some memory in error conditions.