Re: [xml] Memory leak problem

Thank you!  I will Google and see if they have an AIX version.


-----Original Message-----
From: Lara Blatchford [mailto:lara blatchford nteligen com] 
Sent: Tuesday, November 26, 2019 2:34 PM
To: Eric Eberhard <flash vicsmba com>; 'BR Chrisman' <brchrisman gmail com>
Cc: xml gnome org
Subject: RE: [xml] Memory leak problem

Have you considered running your application under a tool like valgrind to see where it reports leaks?


-----Original Message-----
From: xml <xml-bounces gnome org> On Behalf Of Eric Eberhard
Sent: Tuesday, November 26, 2019 1:47 PM
To: 'BR Chrisman' <brchrisman gmail com>
Cc: xml gnome org
Subject: Re: [xml] Memory leak problem

Thank you for reply.   The problem I was solving for is NS not freeing with xmlFreeDoc(node); (which I did 
after all my nonsense).

I took out that code and it dies in the same place ... perhaps I should break down and load a new libxml2 as 
I would guess that the problem is fixed now.  If not, then I am still missing something.

Like I said, I have used it for decades now and never had a problem.  A memory leak is only a problem when 
... it becomes a problem, otherwise you generally don't notice.  This program is making thousands of XML 
files that are rather small, it frees the documents between each file.  My customer's data has crossed some 
line ... 

Is there a C call to see how much memory one is consuming?  I could likely put that in to try and find it.

Anyone else with ideas please let me know!



-----Original Message-----
From: xml [mailto:xml-bounces gnome org] On Behalf Of BR Chrisman via xml
Sent: Sunday, November 24, 2019 12:57 PM
Cc: xml gnome org
Subject: Re: [xml] Memory leak problem

On Sat, Nov 23, 2019 at 10:04 AM Eric Eberhard <flash vicsmba com> wrote:

I have used libxml2 since it was libxml so I can’t believe I am having this problem.  I’m looking for 
someone smarter than me to help out.

I use only the DOM (memory) parser, and an old version at that:  

I have a program that makes many XML files.  They, alone, are not a problem.  But when a large amount are 
made (100s) it gets a memory error.

After each XML document I make I write them to disk and then free them 
(meaning I thought I was freeing ALL the memory).  This is not the 
case so I assume I am not coding it correctly.  This is what I am 
doing …

Hi Eric,

I think you should be able to use xmlFreeDoc on the doc object, rather than on any particular node.
One call to that cleans the whole document up.
I have looped this under valgrind before with no issues found.

- Brian Chrisman

The node is passed to this function  (xmlNodePtr) named 
freeMe(xmlNsPtr node)

Void freeMe(xmlNSPtr node) {

xmlNsPtr next;

 xmlNsPtr cur;

 cur = node->ns;

 while (cur) {

     next = cur->next;

      if (cur->href) xmlFree((char *) cur->href);

      if (cur->prefix) xmlFree((char *) cur->prefix);

      cur->href = NULL;

      cur->prefix = NULL;

       xmlFree((char *)cur);

      cur = next;


node->ns = NULL;

if (node->type == XML_ELEMENT_NODE ||

     node->type == XML_XINCLUDE_START ||

                              node->type == XML_XINCLUDE_END) {

     cur = node->nsDef;

     while (cur) {

             next = cur->next;

              if (cur->href) xmlFree((char *) cur->href);

               if (cur->prefix) xmlFree((char *) cur->prefix

               cur->href = NULL;

               cur->prefix = NULL;

               xmlFree((char *)cur);

             cur = next;


     node->nsDef = NULL;

    If (node->children)

FreeMe(node->children);                            //recursive



//done I think freeing up all memory

I LEFT out the tests for NULLS and error checking and other silly things so it would not be too long.

It also repeats mostly the exact same code if the node is NS so I won’t bore you.  Don’t use NS much anyway.

Problem is, something is not free()’d up.

So besides the main node and NS is there something else I have to free()?  Better, is there a function that 
I can pass the node and it free()’s everything for me?

Any help – even sample code – would be much appreciated!  Free horse back ride in AZ for a winner?


Eric S Eberhard

VICS (Vertical Integrated Computer Systems)

Voice: 928 567 3529

Cell    : 928 301 7537  (not reliable except for text or if not home)

2933 W Middle Verde Rd

Camp Verde, AZ  86322

Oh – help me out and please join this group.  I need to get large 
numbers of members to take to the politicians.

This might work to just join?

<table border="0" width="100%" cellspacing="0" cellpadding="0" 
style="border-collapse:collapse;"><tr style=""><td height="28" 
style="line-height:28px;">&nbsp;</td></tr><tr><td style=""><table 
border="0" width="280" cellspacing="0" cellpadding="0"
solid #dddfe2;border-radius:3px;font-family:Helvetica, Arial, 
sans-serif;margin:0px auto;"><tr style="padding-bottom: 8px;"><td 
style=""><img class="img"
29&amp;oe=5D00A5A4" width="280" height="146" alt="" 
/></td></tr><tr><td style="font-size:14px;font-weight:bold;padding:8px
8px 0px 8px;text-align:center;">Save The Middle Verde</td></tr><tr><td 
er;">Public group · 228 members</td></tr><tr><td style="padding:8px 
12px 12px 12px;"><table border="0" cellspacing="0" cellpadding="0"
43052248115&amp;source=email_campaign_plugin" target="_blank" 
rel="noopener"><table border="0" cellspacing="0" cellpadding="3" 
align="center" style="border-collapse:collapse;"><tr><td
style="border-bottom:3px solid #4267b2;border-top:3px solid 
#4267b2;color:#FFF;font-family:Helvetica, Arial, 
style="border-top:1px solid #dddfe2;font-size:12px;padding:8px
12px;">This group is to help preserve the Middle Verde River, the 
Middle Verde Character area as defined in the Town of Camp 
Verde&#039;s General Plan, the 260 
co...</td></tr></table></td></tr><tr style=""><td height="28"

xml mailing list, project page xml gnome org
xml mailing list, project page xml gnome org

xml mailing list, project page xml gnome org

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