Misc bugfixes from scan-build