Re: [xml] Memory tag errors on xmlCleanupCharEncodingHandlers

On Sun, Aug 22, 2010 at 05:20:03PM -0400, Marco Rogers wrote:
I believe I've found a bug, or at least annoying issue in libxml2.

So I've got a library that is using libxml2 heavily. I had to turn on memory
tracking in the so I can inspect the total memory allocated by libxml2.

xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup);



But now I get the Memory tag errors that occur when xml memory isn't
allocated or freed properly.  I've studied this issue a lot because I
thought it might be a problem of mine.  Here's an example thread below (not
mine, just helped me understand the problem).

I understand things now and I've been debugging to track down where this
happens.  Despite what I might be doing in my library, I always get several
memory errors.  I've traced the problem to the
function xmlCleanupCharEncodingHandlers that gets called in

The function calls xmlFree on all of the names of the handlers.  But the
names were not created with xmlMalloc.  They are passed in as literal
strings.  See ecoding.c around line 1351.

  Sounds wrong to me on 2 counts:
    1/ the handler name is up = xmlMemStrdup() line 1286, not the raw
       strring passed to the function call
    2/ libxml2 when compiled with memory debug use a memory wrapper
       which does an xmlMemSetup() equivalent and all functions go
       though that wrapped allocator. If the problem was present even
       the most trivial tests would fail in this mode.

The problem is likely to be somewhere else...


Daniel Veillard      | libxml Gnome XML XSLT toolkit
daniel veillard com  | Rpmfind RPM search engine | virtualization library

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