More warning and memleak fixes

Just as the title suggests.
Cuts down scanbuild warnings.
@bmiklautz static already declared by prototype