Fix defects revealed by coverity