Fixed resource leaks.