Fix resource leaks on read errors
Fix immediate variable reassignment