Fixed some memory leaks in the test/example code.