Should fix all leaks + a typo

Fixes most leaks on Coverity and Cppcheck

Only error from cppcheck is a false positive.

Compiles on FreeBSD 10.0 and actually gets somewhat better with test, even though it still hangs.