[xslt] Fwd: libxml2 memory leak problem
- From: Amar Pol <amarpol1305 gmail com>
- To: xslt gnome org
- Subject: [xslt] Fwd: libxml2 memory leak problem
- Date: Fri, 18 May 2012 05:35:50 -0000
---------- Forwarded message ----------
From:
Amar Pol <amarpol1305 gmail com>
Date: Fri, May 18, 2012 at 10:58 AM
Subject: libxml2 memory leak problem
To:
xml gnome orgHi,
i m using libxml2.7.3 to parse the xml data from buffer by using doc = xmlParseMemory(s.ptr, s.len);
this is resulting in a memory leak, is there any fix on this issue.
I found that xmlFetProp function returns malloced string and we have to explicitly free the memory. but this is not working too. I have tried malloc_trim(0) also.
please provide me some help on this issue.
here is the sample code i m using to parse the xml data.
doc = xmlParseMemory(s.ptr, s.len);
if(doc != 0)
{
for( nodeLevel1 = doc->children;
nodeLevel1 != NULL;
nodeLevel1 = nodeLevel1->next)
{
i = 0; /*initialising counter to zero*/
#ifdef GPS_DEVICE
Trip.LocationCount = 0;
Trip.TripCount = 0;
#endif
abd_syslog(LOG_DEBUG,"\nMain node entry xml\n");
for( nodeLevel2 = nodeLevel1->children;
nodeLevel2 != NULL;
nodeLevel2 = nodeLevel2->next)
{
for( nodeLevel3 = nodeLevel2->children;
nodeLevel3 != NULL;
nodeLevel3 = nodeLevel3->next)
{
variable_name = (xmlChar *) "val";
if(xmlHasProp(nodeLevel3,variable_name ) )
{
value=xmlGetProp(nodeLevel3,variable_name);
return_val = atoi((char * )value);
xmlFree(value);
}
variable_name = (xmlChar *) "employee_id";
if(xmlHasProp(nodeLevel3,variable_name ) )
{
value=xmlGetProp(nodeLevel3,variable_name);
emp.emp_id[i] = atoi((char * )value);
xmlFree(value);
}
}
i++; /*incrementing the row count*/
//abd_syslog(LOG_DEBUG,"\n count of row %ld\n",i);
}
}
}
xmlFreeDoc(doc);
xmlCleanupParser();
malloc_trim(0);
--
Regards&Thanks
Amar Pol
Software Engineer
--
Regards&Thanks
Amar Pol
Software Engineer
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]