I attempted to touch this area of code in WT-6640 but it's more complex than I thought. The problem is this:
- If we get an error, we should hit API_END_RET_NOTFOUND_MAP and restore the old dhandle because we will still have a session.
- Some of the session resources (like its txn) can be freed before failing meaning that we can error out, jump to API_END_RET_NOTFOUND_MAP and dereference null by trying to operate on the txn.
- It may be helpful to look at how it worked before
WT-6556as this was where the original bug crept in.