Hello,

With an example, it will probably be more easy to understand my problem. In
the example below, I would expect myMalloc and myFree to be called in
main(). But this is not the case. Though if I call for instance
xmlGetNodeContent(), myMalloc() is called, a xmlChar * is returned which I
should free with xmlFree(). But since xmlFree() does not work on memory
allocated with myMalloc().

....

What did I do wrong ?

Alexandre.



#include <stdio.h>
#include <string.h>
#include <gdome.h>
#include <libxml/xmlmemory.h>


void * myMalloc(size_t size);
void myFree(void * addr);

void * myMalloc(size_t size){ printf("Hello boys\n"); return NULL;}
void myFree(void * addr){ printf("You are free now !\n");}

void setMemHooks(void)
{
       xmlInitMemory(); /* probably useless */
xmlMemSetup(myFree,myMalloc,xmlMemRealloc,xmlMemoryStrdup);
}

int main (int argc, char **argv)
{
        void * addr;
size_t l=10;

setMemHooks();
 addr = xmlMalloc(l);
xmlFree(addr);

return EXIT_SUCCESS;

}


---------- Forwarded message ----------
From: Alexandre Gouraud <>
Date: 2011/3/7
Subject: Re: [xml] Memory Bug detection for gdome
To: veillard


Hello Daniel,

Thank you for your answers. There is still something I don't get.

I setup my own memory allocation functions with xmlMemSetup(myFree,
myMalloc, ...).
If I put a breakpoint into myFree and myMalloc, I can see that each time a
myMalloc is called. It is usually when a libxml2 function is called which
need memory. But I never stop in myFree(). Even when xmlMemFree() itself is
called. I have the feeling that if xmlMemFree where called by an libxml2
function, myFree() would be called. But when gdome direclty call xmlMemFree,
it is not hooked.

So what functions are hooked with xmlMemSetup() ? xmlMemFree() or xmlFree()
or both ? xmlMemMalloc or xmlMalloc or both ?
What calls are targeted ? only libxml2 code or even user code ?

And what is the difference between xmlMemSetup and xmlGcMemSetup ? shall I
use both to make sure every memory allocation routine is hooked?

Thank you for your answer in advance,

Alexandre.


2011/3/2 Daniel Veillard

On Wed, Mar 02, 2011 at 09:10:47AM +0100, Alexandre  wrote:
> > Hello,
> >
> > I am currently trying to run gdome tests under cygwin but get segfaults.
> > Since I can't find with the debuger where the memory corruption occurs, I
> > tried to use the memory allocation hooks provided by the library. I have
> > written my own very simple memory allocator: One big chunk of memory is
> > allocated at first, and then pieces of this big chunk are provided on
> > demand. The memory is never freed (and I never run out of memory in this
> > particular case). I setup this memory allocator with:
> >
> > xmlMemSetup(myFree, myMalloc, myRealloc,xmlMemStrdup);
> >
> > And put this at the very begining of the test.
> >
> > I get the results below. I was expecting the "Malloc at 0x... of ..."
> which
> > are produced by my own memory allocation routines. But I was not
> expecting
> > this
> >
> > "Memory tag error occurs: 0x...
> > bye
> > xmlMemFree(...) error"
> >
> > Which indicates that not all memory allocation routines have been hooked.
> I
> > suspect this is internal to the libxml. could this indicate a memory bug
> in
> > the library ?
> > I have libxml2 version 2.7.7
>
>   I compile and run libxml2 with full regression tests using the memory
> debug, so I doubt it's a libxml2 issue. But if gdome modify the tree
> with a piece of memory allocated by malloc and then tries to free the
> tree you will get this problem.
>
> Daniel
>
>

-- 
Alexandre



-- 
Alexandre
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to