Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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 libxml2,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.....
Posted
Comments
Mohibur Rashid 24-May-12 23:13pm    
Please try to debug and figure out exactly what line it fails

1 solution

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.....

Actually the issue was of memory(it's not that,what u r 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...

but one thing i will do i.e i will give u the the URL which helped me to get out of this....

hope some at least get's help out of this.....

if it fulfills your requirement then don't forget to up-vote this answer as i will be taken as first choice by someone else.....THANK Q ....LOVE UR CODE.... ENJY UR CODING....
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900