fix valgrind warnings on other platforms

I only checked FreeBSD with valgrind and made the other changes as they
seemed fitting.
Valgrind doesn't work as well on these platforms, FreeBSD might be the
best of these.

Again, all of these were no real problems, but fixing warnings
in valgrind might help when real issues occur later on.