Fix Valgrind issues

This fixes Valgrind warnings that occur when running tests. It also fixes the crash in #825.

@CTrabant: I suppose you will want to include the fixes for libmseed upstream.