Fix memory leak for reserving new arrays