More fixes for resource leaks