Changed var and mesh name copy to strdup, and added frees on exceptions