My guess is that you are running into a race condition with threading. Cb1 is reallocating the array while your parser is trying to use it. After the realloc the old address is no longer valid and that is where your invalid read is coming from. You'll need to put a lock (perhaps a reader/writer lock) around the array to keep from hitting this problem. If it's possible, try running this code single-threaded to see if the problem reproduces. If it doesn't then it's a threading problem, otherwise it's something else entirely.
Talljoe
2009-06-04 21:18:12