fix resource leak issues