Fix some warnings, leaks, found by cppcheck

Closes #525
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>