fix vi memory allocation/deallocation problems