Fix NULL pointer  segfault