fix a few code defects detected by coverity scan