Core/Misc: Fixed a bunch of issues found by static analysis