There's a fair bit of code there so tracking bugs down by inspection will be a slow process.
To get an idea where the problem is I suggest you selectively disable parts of the message processing until you get to the part that causes the problem.
If you simply print out and discard each sentence, does it keep working?
How about of you try and parse the message ID, then skip all the following processing?
My main area of suspicion is that code in mytok which seems to be copying a token from the front of the buffer. None of the calls to it seem to handle the null return case, and I also wonder what would happen if it ran off the end of the source string without finding a separator. It's used extensively and it would only need to fail once to cause mayhem and memory corruption.