Use trap to release lock