I am not sure it is the reason for this case, but something is wrong there, because if the global `T` is already set, then there is no `REF` done to `T`, but the function does always to `UNREF` at the end.
It should do first `t = tmb.t_gett();` and then `if(t == NULL || t == T_UNDEFINED)` do `tmb.t_check(msg, &_branch)` and on success retrieve `T` with another `tmb.t_gett()`. If `t_check()` had to be done, then `REF` was done and `UNREF` has to be done at the end.