Check the pointer is correctly set to avoid SEGV

* check pointer to avoid SEGV from race condition