Fix incorrect code leading to memory error.