move winfree and winunlock in try block