fixed all the issues reported by the clang static analyzer

some potential leaks and one potential access to freed memory