开发者

libxml2 crash on second use on Windows

I've been using libxml2 push parsing (SAX) to parse an incoming XML stream, this works well first time but crashes on the second attempt every time, my code looks like this:

xmlSAXHandler saxHandler;
memset(&saxHandler, 0, sizeof(m_SaxHandler));
xmlSAXVersion(&saxHandler, 2);
saxHandler.initialized = XML_SAX2_MAG开发者_如何学CIC;  // so we do this to force parsing as SAX2.
saxHandler.startElementNs = &startElementNs;
saxHandler.endElementNs = &endElementNs;
saxHandler.warning = &warning;
saxHandler.error = &error;
saxHandler.characters = &characters;

xmlParserCtxtPtr pSaxCtx = xmlCreatePushParserCtxt(&m_SaxHandler, this, 0, 0, 0);

I then feed in the XML stream using xmlParseChunk() and use the callbacks to process the data, once parsing is complete, I call xmlFreeParserCtxt(pSaxCtx) to free the context. As I mentioned, this all works perfectly on the first set of data but when the code is run again I get an access violation, the stack trace is:

ntdll.dll!_RtlpWaitOnCriticalSection@8()  + 0x99 bytes 
ntdll.dll!_RtlEnterCriticalSection@4()  + 0x168d8 bytes 
ntdll.dll!_RtlpWaitOnCriticalSection@8()  + 0x99 bytes  
ntdll.dll!_RtlEnterCriticalSection@4()  + 0x168d8 bytes 
libxml2.dll!xmlGetGlobalState()  Line 716   C
libxml2.dll!__xmlDefaultBufferSize()  Line 814 + 0x5 bytes  C
libxml2.dll!xmlAllocParserInputBuffer(xmlCharEncoding enc)  Line 2281 + 0x5 bytes   C
libxml2.dll!xmlCreatePushParserCtxt(_xmlSAXHandler * sax, void * user_data, const char * chunk, int size, const char * filename)  Line 11695 + 0x9 bytes    C
TestApp.exe!XMLProcessor::XMLProcessor(const wchar_t * szHost=0x00d3d80c, const wchar_t * szUri=0x00d3db40, bool secure=false)  Line 16 + 0x19 bytes C++
TestApp.exe!WorkerThread::ThreadProc(void * lpParameter=0x00a351c0)  Line 34 + 0x15 bytes C++
kernel32.dll!@BaseThreadInitThunk@12()  + 0x12 bytes 
ntdll.dll!___RtlUserThreadStart@8()  + 0x27 bytes 
ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes

It seems to be trying to lock a critical section which is either non-existant or corrupted but I cannot figure how/why it works first time and not second.

Any ideas?

Thanks, J


Are the two calls in different threads?

Have you called the xmlInitParser function to initialize the library. A missing call to xmlInitParser will produce a call stack like yours in multi-threaded applications.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜