Fix resource leak problem