Use auto_alloc_array() and remove non-automatic memory deallocation