Convert t_vcm to C++, plugging a memory leak