remove some memory allocation and deallocation errors