Properly unlock resource if cancel is pressed