Fix cppcheck warnings

Please review my patches.