Temporary variables are referenced beyond their lifetime
Promoting them to top level scope in main() solves this. This is only happening on the 'sudo' code path.
@avolio for nightly mainly, but can go into future patch as no interface is changed - just to avoid branching.