Corrections found by Valgrind 

These fixes were found when running the client under valgrind