Fix some issues from SCA - v2 - against ceph:next

Update version of pull request #428/#440.
- removed two of the patches, since they need to get reworked.
- pull request against next 

---
Includes smaller issues like:
- reduce scope of local variables
- same expression on both sides of '||'
- remove unused local variable
- don't return bool if return value is int
- return result of function calls
- use static_cast instead of C-Style cast
- fix dereferencing after deallocation

And these two issues (please check them carefully)
- fix malloc memory leak