Fix potential deferencement of null pointer
Fix potential dereferencement of NULL pointer
Plug a memory leak