Re: [xml] Memory leak problem

2019-12-21 Thread Daniel Veillard via xml
  Hi Eric,

sorry, I'm very late to the thread, but in case you still have issues:

 1/ yes xmlFreeDoc is the right way to free the whole memory of the
document, you may be missing freeing other bits left and right if you
don't use it
 2/ you can debug memory allocation by running valgrind but there is another
libxml2 only way:
- recompile after configuring with --with-mem-debug , when doing so
  xmlFree() and free() are not interchangeable anymore but all allocations
  by libxml2 are tracked
- xmlMemoryDump() then saves to a .memorylist file all the allocations
  made by libxml2 which were not freed by libxml2 you can also call it
  from a debugger to track dynamically
that's how I removed most leaks in libxml2
 3/ valgrind is indeed the simplest tool if you can't recompile or
if you mixed alloc and frees from the C library and libxml2 layers
I would still encourage to avoid that mixing, some of the special features
of the libxml2 DOM tree are that sometimes the same string should be freed
sometime it can't e.g. textual node content.
 4/ the library use a dictionary which can be reused accross documents
and only xmlCleanupParser() frees that up but you should be very careful
about in threaded context or in programs potentially using libxml2 in
other modules.

  that said I hope your problem is solved now, sorry for being so late

Daniel

On Sat, Nov 23, 2019 at 10:53:01AM -0700, Eric Eberhard 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:
> libxml2-2.7.3
> 
>  
> 
> 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 .
> 
>  
> 
> 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
> 
> } 
> 
> 
> 
> xmlFreeDoc(node);
> 
>  
> 
> //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?
> 
>  
> 
> E
> 
>  
> 
>  
> 
> 
> 
>  
> 
>  
> 
>  
> 
>  
> 
> Eric S Eberhard
> 
> VICS (Vertical Integrated Computer Systems)
> 
> Voice: 928 567 3529

Re: [xml] Memory leak problem

2019-11-27 Thread Nick Wellnhofer

Hi Eric,

I'd use AddressSanitizer to debug this kind of problem. It's built into recent 
clang and gcc versions but probably doesn't support AIX. If you can produce a 
stand-alone test program that exhibits the memory leak, you could debug it 
under Linux, though.


Another option is libxml2's built-in memory debugging:

http://xmlsoft.org/xmlmem.html

It's rather limited but it might be your only option if you can't use external 
tools.


Nick
___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


Re: [xml] Memory leak problem

2019-11-26 Thread Eric Eberhard
Thank you!  I will Google and see if they have an AIX version.

E

-Original Message-
From: Lara Blatchford [mailto:lara.blatchf...@nteligen.com] 
Sent: Tuesday, November 26, 2019 2:34 PM
To: Eric Eberhard ; 'BR Chrisman' 
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?

Lara

-Original Message-
From: xml  On Behalf Of Eric Eberhard
Sent: Tuesday, November 26, 2019 1:47 PM
To: 'BR Chrisman' 
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!

Thanks,

Eric

-Original Message-
From: xml [mailto:xml-boun...@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  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:  
> libxml2-2.7.3
>
>
>
> 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
>
> }
>
>
>
> xmlFreeDoc(node);
>
>
>
> //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?
>
>
>
> E
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Eric S Eberhard
>
> VICS (Vertical Integrated Computer Systems)
>
> Voice: 928 567 3529
>
> Cell

Re: [xml] Memory leak problem

2019-11-26 Thread Liam R E Quin
On Tue, 2019-11-26 at 22:48 -0700, Eric Eberhard wrote:
> Thank you much.  I am on AIX (IBM). 

OK. Check the man page for malloc
man 3 malloc
and see if there are environment variables to check each allocation.

Years ago (1980s) i ended up writing wrappers around malloc and free
that took an extra string argument to identify the object, so i could
count and see which objects were leaking!

> I really appreciate your giving me those function names -- I will
> Google them and see if they work on AIX.
If not, maybe you could simulate 10,000 documents and see what happens?

> AIX has "dbx" as the debugger .. being old I am not good at it and
> tend to use debug code rather than depend on the dbx.  I don't even
> know how to ask dbx to tell me what my memory usage is.
I don't know if it can.

> 
> I will report back to the group when done and solved.  
> 
> Have a GREAT Thanksgiving,

Thanks! (that was in October here :D but happy US Thanksgiving to you)

Liam

-- 
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org

___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


Re: [xml] Memory leak problem

2019-11-26 Thread Eric Eberhard
Thank you much.  I am on AIX (IBM).  Performance is a non-issue.  We process 
2-4 million XML documents per day (in and out) using HTTP POST.  On the main 
server which handles 20,000+ orders per day on automated lines that give 2-3 
seconds to update inventory, A/R, check credit, rate shop up to 5 carriers, 
collect credit card auths, etc.  This has never been a problem as in forever.  
Where I am having the problem is sending real-time inventory to thousands of 
customers where an XML file is created, written, and "freed" -- always worked 
until a customer reached a certain number if SKUs or perhaps customers that 
need an update.  Some memory somewhere is not being freed.  It could be my 
code.  Or libxlml2.  I am certainly not infallible!  

I really appreciate your giving me those function names -- I will Google them 
and see if they work on AIX.  

I can't use other tools -- it is integrated with our database manager.  So C is 
my only option.  I don't know if it is something in my code, something in 
libxml2 -- which is truly excellent -- maybe I should first update to the 
latest version and see?  And then try debugging.  I am pretty careful on my own 
memory management but ... I still make mistakes and I thank you for the 
pointers.

G -- you'd think after 40 years of C coding -- and since 1988 on AIX -- I 
would know these things, but - there is always something else to learn.  I 
contribute a lot to help other people on this forum and I am glad that people 
like you are willing to help me!  I need it!

AIX has "dbx" as the debugger .. being old I am not good at it and tend to use 
debug code rather than depend on the dbx.  I don't even know how to ask dbx to 
tell me what my memory usage is.  

I will report back to the group when done and solved.  

Have a GREAT Thanksgiving,

E

-Original Message-
From: Liam R E Quin [mailto:l...@holoweb.net] 
Sent: Tuesday, November 26, 2019 7:17 PM
To: Eric Eberhard ; 'BR Chrisman' 
Cc: xml@gnome.org
Subject: Re: [xml] Memory leak problem

On Tue, 2019-11-26 at 11:47 -0700, Eric Eberhard wrote:
> Is there a C call to see how much memory one is consuming?  I could 
> likely put that in to try and find it.

Depends on your operating system - there are also environment variables you can 
se that affect the bahaviour of malloc() in various ways, and that may help 
you. Try malloc_info() maybe,
   int malloc_info(int options, FILE *stream); where options must be 0 (duh).

If you don't have that, malloc_stats() prints to stderr, and if you don't ahve 
that, mallinfo() returns a struct.

On some systems, getrusage() will tell you about your process or thread's 
memory usage. Some other systems have vtimes() instead.

There's a variety of C debugging tools, but it depends on the operating system 
and environment as to which will be available.

It might be that a change in some external library has moved something around 
in memory and exposed a bug in your code (or in someone else's).

Incidentally, for production work, it's worth considering moving to an XSLT 3 
engine - whether Saxon 9 (Java, C# and C) or another one.

In a recent class exercise (in a course i was running on XSLT 3) people 
reported times of 6 seconds or so to write 10,000 HTIL files from an XML input 
document, and 10 seconds to do the same in streaming mode.
This was using Saxon EE in Java, for what it's worth. So it might be acceptably 
fast that you can consider moving to XSLT 3 and get the engineering benefits of 
type checking, too.

Liam

--
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/ XSL/XQuery/Web/Text 
Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org



___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


Re: [xml] Memory leak problem

2019-11-26 Thread Liam R E Quin
On Tue, 2019-11-26 at 11:47 -0700, Eric Eberhard wrote:
> Is there a C call to see how much memory one is consuming?  I could
> likely put that in to try and find it.

Depends on your operating system - there are also environment variables
you can se that affect the bahaviour of malloc() in various ways, and
that may help you. Try malloc_info() maybe,
   int malloc_info(int options, FILE *stream);
where options must be 0 (duh).

If you don't have that, malloc_stats() prints to stderr, and if you
don't ahve that, mallinfo() returns a struct.

On some systems, getrusage() will tell you about your process or
thread's memory usage. Some other systems have vtimes() instead.

There's a variety of C debugging tools, but it depends on the operating
system and environment as to which will be available.

It might be that a change in some external library has moved something
around in memory and exposed a bug in your code (or in someone else's).

Incidentally, for production work, it's worth considering moving to an
XSLT 3 engine - whether Saxon 9 (Java, C# and C) or another one.

In a recent class exercise (in a course i was running on XSLT 3) people
reported times of 6 seconds or so to write 10,000 HTIL files from an
XML input document, and 10 seconds to do the same in streaming mode.
This was using Saxon EE in Java, for what it's worth. So it might be
acceptably fast that you can consider moving to XSLT 3 and get the
engineering benefits of type checking, too.

Liam

-- 
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org

___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


Re: [xml] Memory leak problem

2019-11-26 Thread Lara Blatchford
Have you considered running your application under a tool like valgrind to see 
where it reports leaks?

Lara

-Original Message-
From: xml  On Behalf Of Eric Eberhard
Sent: Tuesday, November 26, 2019 1:47 PM
To: 'BR Chrisman' 
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!

Thanks,

Eric

-Original Message-
From: xml [mailto:xml-boun...@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  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:  
> libxml2-2.7.3
>
>
>
> 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
>
> }
>
>
>
> xmlFreeDoc(node);
>
>
>
> //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?
>
>
>
> E
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> 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.
&

Re: [xml] Memory leak problem

2019-11-26 Thread Eric Eberhard
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!

Thanks,

Eric

-Original Message-
From: xml [mailto:xml-boun...@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  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:  
> libxml2-2.7.3
>
>
>
> 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
>
> }
>
>
>
> xmlFreeDoc(node);
>
>
>
> //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?
>
>
>
> E
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> 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.  
> https://www.facebook.com/groups/286143052248115/
>
> This might work to just join?
>
>  style="border-collapse:collapse;"> style="line-height:28px;"> border="0" width="280" cellspacing="0" cellpadding="0" 
> style="borde

Re: [xml] Memory leak problem

2019-11-24 Thread BR Chrisman via xml
On Sat, Nov 23, 2019 at 10:04 AM Eric Eberhard  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:  libxml2-2.7.3
>
>
>
> 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
>
> }
>
>
>
> xmlFreeDoc(node);
>
>
>
> //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?
>
>
>
> E
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> 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.  
> https://www.facebook.com/groups/286143052248115/
>
> This might work to just join?
>
>  style="border-collapse:collapse;"> style="line-height:28px;"> width="280" cellspacing="0" cellpadding="0" 
> style="border-collapse:separate;background-color:#ff;border:1px solid 
> #dddfe2;border-radius:3px;font-family:Helvetica, Arial, sans-serif;margin:0px 
> auto;"> src="https://scontent.fhhr1-1.fna.fbcdn.net/v/t1.0-0/c0.0.584.305a/p320x320/50521766_10218655229077782_1167298564032823296_n.jpg?_nc_cat=101_nc_ht=scontent.fhhr1-1.fnaoh=d725734d9126b706d402e635740dcd29oe=5D00A5A4;
>  width="280" height="146" alt="" /> style="font-size:14px;font-weight:bold;padding:8px 8px 0px 
> 8px;text-align:center;">Save The Middle Verde style="color:#90949c;font-size:12px;font-weight:normal;text-align:center;">Public
>  group · 228 members style="border-collapse:collapse;width:100%;"> style="background-color:#4267b2;border-radius:3px;text-align:center;"> style="color:#3b5998;text-decoration:none;cursor:pointer;width:100%;" 
> href="https://www.facebook.com/plugins/group/join/popup/?group_id=286143052248115source=email_campaign_plugin;
>  target="_blank" rel="noopener"> cellpadding="3" align="center" style="border-collapse:collapse;"> style="border-bottom:3px solid #4267b2;border-top:3px solid 
> #4267b2;color:#FFF;font-family:Helvetica, Arial, 
> sans-serif;font-size:12px;font-weight:bold;">Join 
> Group 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 Verdes General Plan, the 260 
> co... style="line-height:28px;">
>
>
>
> ___
> xml mailing list, project page  http://xmlsoft.org/
> xml@gnome.org
> https://mail.gnome.org/mailman/listinfo/xml
___
xml mailing list, project page  

[xml] Memory leak problem

2019-11-23 Thread Eric Eberhard
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:
libxml2-2.7.3

 

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 .

 

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

} 



xmlFreeDoc(node);

 

//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?

 

E

 

 



 

 

 

 

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.
https://www.facebook.com/groups/286143052248115/

This might work to just join?

https://scontent.fhhr1-1.fna.fbcdn.net/v/t1.0-0/c0.0.584.305a/p320x320/
50521766_10218655229077782_1167298564032823296_n.jpg?_nc_cat=101_nc_ht=
scontent.fhhr1-1.fnaoh=d725734d9126b706d402e635740dcd29oe=5D00A5A4
" width="280" height="146" alt="" />Save The Middle VerdeP
ublic group . 228 membershttps://www.facebook.com/plugins/group/join/popup/?group_id=2861430522
48115source=email_campaign_plugin" target="_blank"
rel="noopener">Join
GroupThis
group is to help preserve the Middle Verde River, the Middle Verde Character
area as defined in the Town of Camp Verdes General Plan, the 260
co...

 

___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml