Check pointer before deleting

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

Signed-off-by: Jiantao He <hejiantao5@gmail.com>
Merge pull request #2685 from hejiantao5/patch-1

Check the pointer before deleting

Reviewed-by: Loic Dachary <loic-201408@dachary.org>