Fixes for some of the defects detected by coverity
Fix for defect CID 51682
Fix for defect CID 51684
Fix for defects CID 51683 and 51684
Fix for defects CID 51684 and 51666
Fix for defects CID 51686, 51685, 51687 and 51667