fix the bug for null reference in auto close