cleanup the autorevision.h.new file when it is not moved to replace autorevision.h

Patch by rbt
closes ticket:4018
Put back debug line that was incorrectly removed.
Fix string subscript out of range.
Fix vector subscript out of range.
Fix iterator erasing from std::list

Fix data race condition.
Fixes ticket:4213
Fixes ticket:3228
Merge branch 'bugfixes' into 3.1