Fixed releasing locks after exception