Fix resource leak