Add null check after mrb_malloc and mrb_realloc for state