Fixed deadlock caused by returning without releasing lock.