Fix potential bugs from coverity scan