Fix a resource closure issue