Corrected memory allocation