Fix memory leaks found by clang static analyser