[FixRM #8312] - Fix file handle leaks

Fix file handle leaks for [SeeRM #8312]