libxml2第二次在Windows上使用时崩溃 [英] libxml2 crash on second use on Windows

查看:339
本文介绍了libxml2第二次在Windows上使用时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用libxml2推送解析(SAX)来解析传入的XML流,这第一次工作良好,但崩溃第二次尝试每次,我的代码如下:

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_MAGIC;  // 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);

然后我使用 xmlParseChunk $ c>并使用回调来处理数据,一旦解析完成,我调用 xmlFreeParserCtxt(pSaxCtx)释放上下文。正如我所提到的,这一切都完美地工作在第一组数据,但当代码再次运行我得到访问冲突,堆栈跟踪是:

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.

任何想法?

谢谢,
J

Thanks, J

推荐答案

您是否已调用 xmlInitParser 函数来初始化库。缺少对 xmlInitParser 的调用将在多线程应用程序中产生类似于您的调用堆栈。

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.

这篇关于libxml2第二次在Windows上使用时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆