Avoid an unnecessary copy of a string.
Limit variable scope.

Issue found by cppcheck.
Pre instead of post increment a variable.

Issue found by cppcheck.
Validate a pointer before deferring it.

The problem was introduced in 818ffad0, David Mikos please review this
patch.

Issue found by cppcheck.
Remove an unused private function.

Issue found by cppcheck.