Fix resource leaks.