Fix some cppcheck SCA issues

Fixed issues:
- remove unused variable(s)
- fix possible NULL pointer dereference
- remove not needed code
- reduce scope of local variable(s)