reauthorize: Fix a number of bugs caught by Coverity