[#1273] Fix resource leaks in test