Re: [xml] xmlNewNode allocates memory that ist already in use
- From: Daniel Veillard <veillard redhat com>
- To: t kutzer bebro de
- Cc: xml gnome org
- Subject: Re: [xml] xmlNewNode allocates memory that ist already in use
- Date: Mon, 17 Feb 2003 08:18:44 -0500
On Mon, Feb 17, 2003 at 01:42:09PM +0100, t kutzer bebro de wrote:
Then following problem occured: I had to compile my project with byte
alignment, and suddenly libxml2 didn't work any more.
libxml2 has been compiled on a variety of systems, 31 32 and 64 bits
mostly, an no such alignment problem has been raised so far. Moreover
you're the only one in the position to debug it so please do so ! Just
saying "it doesn't work" and not doing the effort of finding why doesn't
give me a good incentive to help you on further problems. I hope it
makes sense to you !
Following two lines of code:
temp2 = (xmlChar *)IntToStr(i_value).c_str();
nodePtr3 = xmlNewTextChild(NodePtr3, NULL, (xmlChar *)"value",
temp2);
After the call of xmlNewTextChild there is just "0" in the part of memory
to which temp2 adresses.
I attached the fault to following lines in tree.c xmlNewNode(...)
cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));
if (cur == NULL) {
xmlGenericError(xmlGenericErrorContext, "xmlNewNode : malloc
failed\n");
return(NULL);
}
memset(cur, 0, sizeof(xmlNode));
xmlMalloc allocates a part of memory to which temp2 also adresses.
xmlMalloc is defined to be malloc() as provided by the C library.
So it seems you C runtime is buggy because it reallocated a range of
addresses which it allocated previously. Or memset() is bugged because
it addressed bytes outside the range just allocated.
When I compile the programm with these lines of code the fault doesn't
occur:
String s = IntToStr(i_value);
temp2 = (xmlChar *)s.c_str();
nodePtr3 = xmlNewTextChild(NodePtr3, NULL, (xmlChar *)"value",
temp2);
Has anyone an idea how I can eliminate this fault?
Seems to indicate that the problem is in the memory management of
your C runtime, or that you C++ runtime has trouble passing const strings
to an underlying function in C.
Daniel
--
Daniel Veillard | Red Hat Network https://rhn.redhat.com/
veillard redhat com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]