Bug fix for multithread resource release