Coverity fixes

Hi, 

Please review and apply these patches. Thanks, 

Xing