Fix memory allocation error for -DVALGRIND