Fix memory allocation error