fix thread resource leak