Memfixes

Fixes for issues flagged by Dr.Memory and the MSVC static analysis tool, along with a few misc code hygiene improvements
Not that I know of :/. I'm trying to think of similar utility macros but coming up blank :P.