fix memory leak in register_variable_in_vm functions