memory stuff

Free memory in destructor, replace remaining malloc/free with
new/delete.