Fix memory leaks on failures and an unused variable as reported by cppcheck 1.63