Fix a null pointer on close issue