More warning and memleak fixes

Just as the title suggests.
Cuts down scanbuild warnings.
Why did you remove the static her?