Actually, this is a bad way to exit the program. I suggest you switch exit(1); to abort();. This way you should get a core dump with a stack trace, showing where the call is coming from and which value is the culprit.

Oh, you mustn't think I think YOU wrote that - it's a holdover from old circle code.

And no, the rest of the code around that point looks fine to me. It's not this part of the code that's at fault, even if it is the part that is failing.
Somewhere, you are sending a char_data to this function when already in nowhere (ie. "in menu/dead") or you are passing in a NULL char_data.
However, knowing that makes it no more possible for us to help you. We need more info. And abort() dumps core (unless on an ARM system), so it will supply the needed core dump for you to supply us with backtraces, info, etc.
exit(1) just lets the autorun script know something didn't go well.