Fix "high-impact" coverity false-positive warnings outside of tests.

Let's fix all the current "high impact" coverity issues that are outside of the unit tests. (For other issues, see siblings of this ticket.)