Fix cppcheck reports:
- (style) Same expression on both sides of '=='
- (style) Same expression on both sides of '||'
- (error) Mismatching allocation and deallocation
- memory leaks
- resource leaks
Merge pull request #1163 from serval2412/master

Fix cppcheck reports: