This essentially sanitize undo sculpt code, no context were passed there, but _end() function was then accessing G_MAIN to retrieve a window manager...
Note that there are one or two places where a context is not available, so those functions have to accept a NULL context then.
This should become also useful for fixing T82388 hopefully.