fix some bugs in the c++ tests.

these were discovered with valgrind