bug-20850 - fixed a number of memory leaks identified by valgrind.