More warning and memleak fixes

Just as the title suggests.
Cuts down scanbuild warnings.
@akallabeth makes perfect sense ;). I personally prefer it to have static in declaration and definition. But that's just my preference.