Check the pointer before deleting

Here I think should check the pointer, to avoid potential risk