valgrind memcheck gcs fixes

This is the first part of https://github.com/PhoenixPilot/PhoenixPilot/issues/174 and
a work in progress. Each issue should be fixed by one commit. Comments are welcome.