fix segfault, add initialize var && compare with NULL