Fix some bugs and a memleak in the testsuite.