Some fixes detected by xcode analyze
Merge pull request #6198 from dumganhar/xcode-analyze-fix

Some fixes detected by xcode analyze