Merge pull request #1161 from kgaillot/fixes
Fix: various: issues discovered via valgrind and coverity