Fix some warnings, leaks, found by cppcheck