fixed release of mutex when exceptions occur