compiler and memory leak fixes

This applies the fix from issue #18, fixes non-static builds with `./configure && make` and fixes two compile warnings.

As an aside: 7 of the 9 tests in make check fail here, both in my repo and upstream :/