cppcheck experiment. A couple of memory leaks fixed