fix a null pointer deref bug