Fix potential NULL pointer dereference