Various fixups and checks to make scan-build happy