[ots] Fix (potential) use-after-free bugs

Make sure we don’t try to access the table after deleting it. Not all
the changed files are affected, but I changed them all for the sake of
consistency.