Cb_exit - the C implementation