This is an unsatisfying fix, as I wasn't able to find a single place to check if the main frame has been deleted before processing an event. Instead, I put it in a few places that I was able to find that led to dereferencing NULL. It's possible that adding it to do_execution would have been sufficient or that I should add it to more places.
In any event, this fixes the crashes that I was able to reproduce reliably (MOUSEON and WINDOWFILEEDIT).