Leak fixes

Latest results of studying valgrind logs.  Meanwhile, @sigurdteigen fixed some of the same leaks as me; two of those I've dropped on rebasing, the third survives as the abuse fix here (I'm nervous of a free(undefined) happening, otherwise).