Fix a few memory leaks

Detected by Cppcheck