Assorte leak fixes

Our daemons were leaking like sieves.  Bishwa ran valgrind, I read its memcheck.log, various leaks were immediately easy to find.  This fixes them (and does a bit of tidy-up while it's about it).

Anyone familiar with the parser: please review the parser-leak-fix particularly closely.  I think I caught all the problems (and, naturally, I ran all the tests in core, although I have rebased since) but it's in code I don't know at all ...