[xml] Rookie Mistake - Leaking memory using xmlParseMemory?



All,
 
I've got to figure that this is a rookie mistake but I have been combing through the docs and mailing list archives and can't seem to sort this one out. I've tried the memory debug procedures, with and without gdb, and couldn't make any headway. Here's what I'm seeing in the output from valgrind:
 
12245== 40 bytes in 10 blocks are definitely lost in loss record 1 of 5
12245==     at 0x1B903D54: malloc (vg_replace_malloc.c:131)
12245==     by 0x1B948138: xmlStrndup (in /usr/lib/libxm2.so.2.5.10)
12245==     by 0x1B9481E3: xmlStrdup (in /usr/lib/libxm2.so.2.5.10)
12245==     by 0x1B95B0F0: xmlNewDoc (in /usr/lib/libxm2.so.2.5.10)
12245==    
12245== LEAK SUMMARY:
12245==     definitely lost:  40 bytes in 10 blocks
12245==     possibly lost:   0 bytes in 0 blocks
12245==     still reachable: 1120 bytes in 40 blocks
12245==     suppressed:    200 bytes in 1 blocks
 
I pulled down a newer version of libxml2 with the same result except I had the code and it points to the creation of the xml version member of the xmlDoc struct using xmlStrdup.  I made a few changes in there too but to no avail. This is the simple program I have reduced it down to:
 
int main(int argc, char **argv) {
  xmlDocPtr doc = NULL;
  xmlNodePtr cur;
  int i = 0;
  char * tmp;
 
  xmlInitParser();
 
  for (i=0;i<10;1++) {
    tmp = malloc((strlen("<foo>bar</foo>")+1);
    strcpy(tmp,"<foo>bar</foo>");
    doc = xmlParseMemory(tmp,strlen(tmp));
    if (doc!=NULL) {
     cur = xmlDocGetRootElement(doc);
     printf("Root: %s\n",cur->name);
     xmlFree(doc);
    }
    free(tmp);
    sleep(1);
  }
  xmlCleanupParser();
 
  return 0;
}
 
I put the sleep in there so that I could watch the process memory size grow using ps externally. I would really appreciate any help that can be provided because I am very impressed with the library's capabilities and could really use it on my current project.
 
Thanks very much in advance,
 
Greg Burklew
TMA
www.techma.com
 
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]