Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在Windows上第二次使用libxml2时崩溃_C++_Windows_Winapi_Libxml2 - Fatal编程技术网

C++ 在Windows上第二次使用libxml2时崩溃

C++ 在Windows上第二次使用libxml2时崩溃,c++,windows,winapi,libxml2,C++,Windows,Winapi,Libxml2,我一直在使用libxml2推式解析(SAX)解析传入的XML流,第一次很好,但每次第二次尝试时都会崩溃,我的代码如下所示: xmlSAXHandler saxHandler; memset(&saxHandler, 0, sizeof(m_SaxHandler)); xmlSAXVersion(&saxHandler, 2); saxHandler.initialized = XML_SAX2_MAGIC; // so we do this to force parsing a

我一直在使用libxml2推式解析(SAX)解析传入的XML流,第一次很好,但每次第二次尝试时都会崩溃,我的代码如下所示:

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()
输入XML流,并使用回调处理数据,解析完成后,我调用
xmlFreeParserCtxt(pSaxCtx)
释放上下文。正如我所提到的,这一切在第一组数据上都非常有效,但当代码再次运行时,我会遇到访问冲突,堆栈跟踪是:

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
它似乎试图锁定一个不存在或已损坏的关键部分,但我无法理解它第一次是如何工作的,而不是第二次

有什么想法吗

谢谢,
这两个调用在不同的线程中吗


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

使用可用的源代码创建调试生成。后期编辑以包含调试生成的真实堆栈跟踪可能是解析器处理程序中的代码导致了冲突。如果它被注释掉了怎么办?嗨,JWood,你找到解决办法了吗?恐怕我们也面临同样的问题Nevermind(实现内存生命周期例程)为我们解决了这个问题