Fix leaking file handle