nuke more malloc and use RAII for file types as well