xmlReaderForMemory crashes on 2nd time call [closed]

痴心易碎 提交于 2019-12-25 16:55:30

问题


after making google for long time also, i am unable to find reason/solution for crashing of xmlReaderForMemory,still with valid parameters.

i have created two parser function using libxml,when i call individually they are working fine.But when i call one after another it is getting crashed on xmlReaderForMemory by giving error s follows:

First-chance exception at 0x7c918fea in nayak.exe: 0xC0000005: Access violation writing location 0x00000010. Unhandled exception at 0x7c918fea in nayak.exe: 0xC0000005: Access violation writing location 0x00000010.

now i am giving the code of the two functions:

FIRST FUNCTION:

 char* CB_omniParser(char *omnistring){

        char *parseResult,;
        const char *fileName = omnistring;   
        char *temp,*texttemp,*result=0; 
        int i,len=0,error;
        xmlTextReaderPtr reader;
        len= strlen(omnistring);
        if(len==0)
                    return 0;   
                reader = xmlReaderForMemory(fileName,len,"",NULL,0);    

        if(reader){

            temp = (char *) GlobalAlloc(GPTR, sizeof(char)*len);
            parseResult = (char *) GlobalAlloc(GPTR,sizeof(char)*len+1);
            while(error=xmlTextReaderRead(reader)) {
                if(error==-1){              
                    return 0; // on failure
                }           
                switch(xmlTextReaderNodeType(reader)) {

                    case XML_READER_TYPE_ELEMENT: 

                        temp = (char *)xmlTextReaderConstName(reader);
                            strcat(parseResult,temp);                   
                            strcat(parseResult,"#");                            

                        xmlTextReaderMoveToElement(reader);                     
                          continue;

                    case XML_READER_TYPE_TEXT:  
                        temp = (char *)xmlTextReaderConstValue(reader); 
                                strcat(parseResult,temp);                           
                                strcat(parseResult,"|");                

                        continue;               

                }   

            }

            xmlFreeTextReader(reader);
            xmlCleanupParser();
            return parseResult;//on success returns the parsed omni string
        }
        else
            return 0; // on failure
    }

Second Function:

   char* CB_xmlParserFromMemory(char *xmlstring){
        char *xmlParseresult;   
        char *temp; 
        int i,len,,error;;

        xmlTextReaderPtr reader1;

        len= strlen(xmlstring);
        if(len==0)
            return 0;
        reader1 = xmlReaderForMemory(xmlstring,len,NULL,NULL,0);


        if(reader1){

            temp = (char *) GlobalAlloc(GPTR, sizeof(char)*len);
            while(error=xmlTextReaderRead(reader1)) {

                if(error==-1){
                    return 0; // on failure
                }           
                switch(xmlTextReaderNodeType(reader1)) {

                    case XML_READER_TYPE_ELEMENT: 

                        temp = (char *)xmlTextReaderConstName(reader1);                 

                            strcat(xmlParseresult,"\"");
                            strcat(xmlParseresult,temp);
                            strcat(xmlParseresult,"\"");
                            strcat(xmlParseresult,":");

                        xmlTextReaderMoveToElement(reader1);     
                          continue;

                    case XML_READER_TYPE_TEXT:              

                        temp = (char *)xmlTextReaderConstValue(reader1); 
                        strcat(xmlParseresult,"\"");
                        strcat(xmlParseresult,temp);
                        strcat(xmlParseresult,"\"");
                        strcat(xmlParseresult,",");
                    continue;               

                }   

            }       
            xmlCleanupParser();     
            xmlFreeTextReader(reader1);     
            GlobalFree(temp);
            return xmlParseresult;//on success returns the parsed omni string   
        }
        else
            return 0; // on failure
    }

both the functions are working individually fine.but if i call one function after another then both crashes at above given place...ith same error..plz help me.....


回答1:


I think it's a lucky day for me as i am having the opportunity to answer my own question...

Now i am happy as it is working perfectly fine at my end with out any issue, the issue was of memory(it's not that, what you are thinking after listening the word issue of memory).

The issue was being raised because of the statement:

     xmlCleanupParser();

as i have used instead of

   xmlInitParser ();

but now i will not give the reason,because you guys should also do some work...

I will give you the the URL which helped me to get out of this....



来源:https://stackoverflow.com/questions/10737606/xmlreaderformemory-crashes-on-2nd-time-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!