Properly clean up mutexes when lock allocation fails