fix check for open file; cppcheck & g++ recommendations