tests: Fix memory leaks in test programs.