Fix resource leaks detected by Coverity.