Fixing some resource leaks.