[xml] Re : Re: Crash on xmlMalloc



Where did you find in my question that I thought that my problem was in other people code ?
I asked some ideas... not lessons !

I had 5 lines of code before my application crash => 2 calls to a function that run from many years in an other context without problems.
One had a bug... a buffer was not enough for 2 bytes => so when XmlMalloc tryed to alloc memory : it crashed.
I found the problem studying where the XmlAlloc tryed to write in memory (using the memory map in eclipse).

I asked my question on the mailing list because I saw some problems using the library in static.
Maybe it could be a problem of configuration or other.

Thank you anyway.


On Thu, Sep 09, 2010 at 11:03:45AM +0200, IMS wrote:
> Hi all,
>
> I'm developing an application using the library libxml2.
> It seams that all was ok but yesterday my application crashed for an unknown
> reason.
> I tried to debug and after some work I found that the line where my
> application crash is the xmlMalloc in the xmlParserCtxtPtr !
>
> I'm using the libxml2 version 2.7.6
> I'm using the autotools
>
> => In the file configure.ac :
> *# libxml2*
> *PKG_CHECK_MODULES(LIBXMLDEPS, libxml-2.0 >= 2.6.8)*
> *AC_SUBST(LIBXMLDEPS_CFLAGS)*
>
> => In the file makefile.am :
> l*ibmxml_la_CPPFLAGS = -Iinclude $(LIBXMLDEPS_CFLAGS) -D_GNU_SOURCE*
>
> This is the back-trace :
>
> *** glibc detected *** /home/mine/buildSVNLocal/web/cgi/config_etat.cgi:
> malloc(): memory corruption: 0x08052840 ***
> ======= Backtrace: =========
> /lib/tls/i686/cmov/libc.so.6(+0x6b591)[0x55f591]
> /lib/tls/i686/cmov/libc.so.6(+0x6e395)[0x562395]
> /lib/tls/i686/cmov/libc.so.6(__libc_malloc+0x5c)[0x563f9c]
> /usr/lib/libxml2.so.2(xmlNewParserCtxt+0x29)[0x3a02d9]
> /usr/lib/libxml2.so.2(xmlCreateMemoryParserCtxt+0x34)[0x3a3d94]
> /usr/lib/libxml2.so.2(xmlSAXParseMemoryWithData+0x34)[0x3bae74]
> /usr/lib/libxml2.so.2(xmlSAXParseMemory+0x2e)[0x3baf3e]
> /usr/lib/libxml2.so.2(xmlParseMemory+0x28)[0x3baf98]
> /home/mine/local/lib/libmxml.so.1(raw_parse_buffer+0x93)[0x15dd0a] //I call
> here xmlParseMemory
>
> This is the function :
>
> xmlParserCtxtPtr xmlNewParserCtxt(void)
> {
>     xmlParserCtxtPtr ctxt;
>
>     ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt));
>     if (ctxt == NULL) {
>               //<- Never see this line !!!
> xmlErrMemory(NULL, "cannot allocate parser context\n");
> return(NULL);
>     }
>     memset(ctxt, 0, sizeof(xmlParserCtxt));
>     if (xmlInitParserCtxt(ctxt) < 0) {
>         xmlFreeParserCtxt(ctxt);
> return(NULL);
>     }
>     return(ctxt);
> }
>
> With a google search I saw some errors with xmlMalloc but not in the same
> context that mine.
> Do you have any ideas ? I need your help.

  Some of the code of the application is corrupting memory, it happen to
corrupt the memory allocation area managed by glibc, and glibc notices
during an allocation from libxml2 but the corruption was done earlier.
Use valgrind to track this down. Don't assume the problem is in other
people code,

Daniel


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